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