Class: Bizside::Redmine::ResultSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bizside/redmine/result_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, status, json_string = nil) ⇒ ResultSet

Returns a new instance of ResultSet.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bizside/redmine/result_set.rb', line 9

def initialize(key, status, json_string = nil)
  @key = key
  @status = status

  if json_string.present?
    json = ActiveSupport::JSON.decode(json_string.force_encoding('UTF-8'))
    @rows = key.present? ? json[key.to_s] : json
    @errors = json['errors']
  else
    warn(status)
  end

  @rows ||= []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/bizside/redmine/result_set.rb', line 7

def errors
  @errors
end

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/bizside/redmine/result_set.rb', line 4

def key
  @key
end

#rowsObject (readonly)

Returns the value of attribute rows.



6
7
8
# File 'lib/bizside/redmine/result_set.rb', line 6

def rows
  @rows
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/bizside/redmine/result_set.rb', line 5

def status
  @status
end

Instance Method Details

#==(target) ⇒ Object



24
25
26
27
28
29
# File 'lib/bizside/redmine/result_set.rb', line 24

def ==(target)
  self.key == target.key &&
    self.status == target.status &&
    self.rows == target.rows &&
    self.errors == target.errors
end

#eachObject



31
32
33
34
35
# File 'lib/bizside/redmine/result_set.rb', line 31

def each
  rows.each do |hash|
    yield hash
  end
end