Class: Height::ListResponse

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/height/list_response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items) ⇒ ListResponse

Returns a new instance of ListResponse.



20
21
22
# File 'lib/height/list_response.rb', line 20

def initialize(items)
  @items = items
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



18
19
20
# File 'lib/height/list_response.rb', line 18

def items
  @items
end

Class Method Details

.build(ary) ⇒ Object



12
13
14
15
# File 'lib/height/list_response.rb', line 12

def build(ary)
  items = ary.map { |item| Height::Model.for(item) }
  new(items)
end

.parse(json) ⇒ Object



5
6
7
8
9
10
# File 'lib/height/list_response.rb', line 5

def parse(json)
  response = JSON.parse(json)
  items = response['list'].map { |item| Height::Model.for(item) }

  new(items)
end

Instance Method Details

#countObject



28
29
30
# File 'lib/height/list_response.rb', line 28

def count
  @items.count
end

#each(&block) ⇒ Object



32
33
34
# File 'lib/height/list_response.rb', line 32

def each(&block)
  @items.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/height/list_response.rb', line 24

def empty?
  count.zero?
end

#lastObject



36
37
38
# File 'lib/height/list_response.rb', line 36

def last
  @items.last
end