Class: Tiltify::Collection
- Inherits:
-
Object
- Object
- Tiltify::Collection
- Defined in:
- lib/tiltify/collection.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#has_next ⇒ Object
readonly
Returns the value of attribute has_next.
-
#has_prev ⇒ Object
readonly
Returns the value of attribute has_prev.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data:, total:, has_prev: nil, has_next: nil) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(data:, total:, has_prev: nil, has_next: nil) ⇒ Collection
Returns a new instance of Collection.
16 17 18 19 20 21 |
# File 'lib/tiltify/collection.rb', line 16 def initialize(data:, total:, has_prev: nil, has_next: nil) @data = data @total = total @has_prev = has_prev @has_next = has_next end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/tiltify/collection.rb', line 3 def data @data end |
#has_next ⇒ Object (readonly)
Returns the value of attribute has_next.
3 4 5 |
# File 'lib/tiltify/collection.rb', line 3 def has_next @has_next end |
#has_prev ⇒ Object (readonly)
Returns the value of attribute has_prev.
3 4 5 |
# File 'lib/tiltify/collection.rb', line 3 def has_prev @has_prev end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/tiltify/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 |
# File 'lib/tiltify/collection.rb', line 5 def self.from_response(response, type:) body = response.body new( data: body["data"].map { |attrs| type.new(attrs) }, total: body["data"].count, has_prev: body["links"] && !body["links"]["prev"].blank?, has_next: body["links"] && !body["links"]["next"].blank? ) end |