Class: RenderRuby::Collection
- Inherits:
-
Object
- Object
- RenderRuby::Collection
- Defined in:
- lib/render_ruby/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
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.
20 21 22 23 24 25 |
# File 'lib/render_ruby/collection.rb', line 20 def initialize(data:, total:, next_cursor:, prev_cursor:) @data = data @total = total @next_cursor = next_cursor @prev_cursor = prev_cursor end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/render_ruby/collection.rb', line 5 def data @data end |
#next_cursor ⇒ Object (readonly)
Returns the value of attribute next_cursor.
5 6 7 |
# File 'lib/render_ruby/collection.rb', line 5 def next_cursor @next_cursor end |
#prev_cursor ⇒ Object (readonly)
Returns the value of attribute prev_cursor.
5 6 7 |
# File 'lib/render_ruby/collection.rb', line 5 def prev_cursor @prev_cursor end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
5 6 7 |
# File 'lib/render_ruby/collection.rb', line 5 def total @total end |
Class Method Details
.from_response(response, type:) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/render_ruby/collection.rb', line 7 def self.from_response(response, type:) body = response.body return new(data: [], total: 0, next_cursor: '', prev_cursor: '') if body.empty? new( data: body.map { |attrs| type.new(attrs) }, total: body.count, next_cursor: body.last['cursor'], prev_cursor: body.first['cursor'] ) end |