Class: Yar::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/Yar/collection.rb,
lib/yar/collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, items:, total:) ⇒ Collection

Returns a new instance of Collection.



16
17
18
19
20
# File 'lib/Yar/collection.rb', line 16

def initialize(data:, items:, total:)
  @data   = data
  @items  = items
  @total  = total
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/Yar/collection.rb', line 5

def data
  @data
end

#itemsObject (readonly)

Returns the value of attribute items.



5
6
7
# File 'lib/Yar/collection.rb', line 5

def items
  @items
end

#totalObject (readonly)

Returns the value of attribute total.



5
6
7
# File 'lib/Yar/collection.rb', line 5

def total
  @total
end

Class Method Details

.from_response(response, key:, type:) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/Yar/collection.rb', line 7

def self.from_response(response, key:, type:)
  body = response.body
  new(
    data: body[key].map {|attrs| type.new(attrs) },
    items: body["items"],
    total: body["total"]
  )
end