Class: LearnWorlds::Collection
- Inherits:
-
Object
- Object
- LearnWorlds::Collection
- Defined in:
- lib/learn_worlds/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:, current_page:, total_pages:) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(data:, total:, current_page:, total_pages:) ⇒ Collection
Returns a new instance of Collection.
16 17 18 19 20 21 |
# File 'lib/learn_worlds/collection.rb', line 16 def initialize(data:, total:, current_page:, total_pages:) @data = data @total = total @current_page = current_page @total_pages = total_pages end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/learn_worlds/collection.rb', line 3 def data @data end |
#next_cursor ⇒ Object (readonly)
Returns the value of attribute next_cursor.
3 4 5 |
# File 'lib/learn_worlds/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/learn_worlds/collection.rb', line 3 def prev_cursor @prev_cursor end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/learn_worlds/collection.rb', line 3 def total @total end |
Class Method Details
.from_response(response, key:, type:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/learn_worlds/collection.rb', line 5 def self.from_response(response, key:, type:) body = response.body puts body.class new( data: body[key].map { |attrs| type.new(attrs) }, total: body.dig("meta", "totalItems"), current_page: body.dig("meta", "page"), total_pages: body.dig("meta", "totalPages").to_i ) end |