Class: Paddle::Classic::Collection
- Inherits:
-
Object
- Object
- Paddle::Classic::Collection
- Defined in:
- lib/paddle/classic/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
-
#initialize(data:, total:) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(data:, total:) ⇒ Collection
Returns a new instance of Collection.
23 24 25 26 |
# File 'lib/paddle/classic/collection.rb', line 23 def initialize(data:, total:) @data = data @total = total end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/paddle/classic/collection.rb', line 4 def data @data end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
4 5 6 |
# File 'lib/paddle/classic/collection.rb', line 4 def total @total end |
Class Method Details
.from_response(response, type:, key: nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/paddle/classic/collection.rb', line 6 def self.from_response(response, type:, key: nil) body = response.body if key.is_a?(String) data = body["response"][key].map { |attrs| type.new(attrs) } total = body["response"]["total"] else data = body["response"].map { |attrs| type.new(attrs) } total = body["response"].count end new( data: data, total: total ) end |