Class: Trolley::Utils::PaginatedArray
- Inherits:
-
Array
- Object
- Array
- Trolley::Utils::PaginatedArray
- Defined in:
- lib/trolley/utils/PaginatedArray.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#records ⇒ Object
Returns the value of attribute records.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(enum, page, pages, records) ⇒ PaginatedArray
constructor
A new instance of PaginatedArray.
Constructor Details
#initialize(enum, page, pages, records) ⇒ PaginatedArray
Returns a new instance of PaginatedArray.
17 18 19 20 21 22 |
# File 'lib/trolley/utils/PaginatedArray.rb', line 17 def initialize(enum, page, pages, records) super(enum) @page = page @pages = pages @records = records end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
4 5 6 |
# File 'lib/trolley/utils/PaginatedArray.rb', line 4 def page @page end |
#pages ⇒ Object
Returns the value of attribute pages.
4 5 6 |
# File 'lib/trolley/utils/PaginatedArray.rb', line 4 def pages @pages end |
#records ⇒ Object
Returns the value of attribute records.
4 5 6 |
# File 'lib/trolley/utils/PaginatedArray.rb', line 4 def records @records end |
Class Method Details
.from_response(response, klass) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/trolley/utils/PaginatedArray.rb', line 6 def self.from_response(response, klass) data = JSON.parse(response) enum = Utils::ResponseMapper.new(response, klass).build page = data.dig('meta', 'page') pages = data.dig('meta', 'pages') records = data.dig('meta', 'records') new(enum, page, pages, records) end |