Class: Paddle::Collection
- Inherits:
-
Object
- Object
- Paddle::Collection
- Defined in:
- lib/paddle/collection.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #first ⇒ Object
-
#initialize(data:, total:) ⇒ Collection
constructor
A new instance of Collection.
- #last ⇒ Object
Constructor Details
#initialize(data:, total:) ⇒ Collection
Returns a new instance of Collection.
22 23 24 25 |
# File 'lib/paddle/collection.rb', line 22 def initialize(data:, total:) @data = data @total = total end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/paddle/collection.rb', line 3 def data @data end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/paddle/collection.rb', line 3 def total @total end |
Class Method Details
.from_response(response, type:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/paddle/collection.rb', line 5 def self.from_response(response, type:) body = response.body data = body["data"].map { |attrs| type.new(attrs) } if body["meta"]["pagination"] total = body["meta"]["pagination"]["estimated_total"] else total = body["data"].count end new( data: data, total: total ) end |
Instance Method Details
#each(&block) ⇒ Object
27 28 29 |
# File 'lib/paddle/collection.rb', line 27 def each(&block) data.each(&block) end |
#first ⇒ Object
31 32 33 |
# File 'lib/paddle/collection.rb', line 31 def first data.first end |
#last ⇒ Object
35 36 37 |
# File 'lib/paddle/collection.rb', line 35 def last data.last end |