Class: AxTrack::Collection
- Inherits:
-
Object
- Object
- AxTrack::Collection
- Defined in:
- lib/ax_track/collection.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#next_cursor ⇒ Object
readonly
Returns the value of attribute next_cursor.
-
#prev_cursor ⇒ Object
readonly
Returns the value of attribute prev_cursor.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
-
.from_response(json_response, key:, type:) ⇒ Object
key is the subset of the json_response for which to create an array type is the class Type to wrap the results from key.
Instance Method Summary collapse
-
#initialize(data:, total:, next_cursor:, prev_cursor:) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(data:, total:, next_cursor:, prev_cursor:) ⇒ Collection
Returns a new instance of Collection.
15 16 17 18 19 20 |
# File 'lib/ax_track/collection.rb', line 15 def initialize(data:, total:, next_cursor:, prev_cursor:) @data = data @total = total @next_cursor = next_cursor.nil? || next_cursor.empty? ? nil : next_cursor @prev_cursor = prev_cursor.nil? || prev_cursor.empty? ? nil : prev_cursor end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/ax_track/collection.rb', line 3 def data @data end |
#next_cursor ⇒ Object (readonly)
Returns the value of attribute next_cursor.
3 4 5 |
# File 'lib/ax_track/collection.rb', line 3 def next_cursor @next_cursor end |
#prev_cursor ⇒ Object (readonly)
Returns the value of attribute prev_cursor.
3 4 5 |
# File 'lib/ax_track/collection.rb', line 3 def prev_cursor @prev_cursor end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/ax_track/collection.rb', line 3 def total @total end |
Class Method Details
.from_response(json_response, key:, type:) ⇒ Object
key is the subset of the json_response for which to create an array type is the class Type to wrap the results from key
7 8 9 10 11 12 13 |
# File 'lib/ax_track/collection.rb', line 7 def self.from_response(json_response, key:, type: ) body = json_response.body new(data: body[key].map { |attrs| type.new(attrs ) }, total: body.dig('count'), next_cursor: body.dig('next'), prev_cursor: body.dig('previous')) end |