Class: NexosisApi::PagedArray
- Inherits:
-
Array
- Object
- Array
- NexosisApi::PagedArray
- Defined in:
- lib/nexosis_api/paged_array.rb
Overview
Generic list base class for list responses
Instance Attribute Summary collapse
-
#item_total ⇒ int
The total number of items available on the server for this collection.
-
#links ⇒ Array of NexosisApi::Link
paging links to first, last pages.
-
#page_number ⇒ int
The current page number represented by this collection.
-
#page_size ⇒ int
The total number of items per page.
-
#total_pages ⇒ int
The total number of pages given the current page size and item total.
Instance Method Summary collapse
-
#initialize(paged_response, item_array = []) ⇒ PagedArray
constructor
A new instance of PagedArray.
Constructor Details
#initialize(paged_response, item_array = []) ⇒ PagedArray
Returns a new instance of PagedArray.
5 6 7 8 9 10 11 12 13 |
# File 'lib/nexosis_api/paged_array.rb', line 5 def initialize(paged_response, item_array = []) self[0..item_array.length] = item_array var_map = { 'pageNumber' => :@page_number, 'totalPages' => :@total_pages, 'pageSize' => :@page_size, 'totalCount' => :@item_total } paged_response.each { |k, v| instance_variable_set(var_map[k.to_s], v) unless var_map[k.to_s].nil? } @links = paged_response['links'].map { |l| NexosisApi::Link.new(l) } unless paged_response['links'].nil? end |
Instance Attribute Details
#item_total ⇒ int
The total number of items available on the server for this collection
29 30 31 |
# File 'lib/nexosis_api/paged_array.rb', line 29 def item_total @item_total end |
#links ⇒ Array of NexosisApi::Link
paging links to first, last pages
33 34 35 |
# File 'lib/nexosis_api/paged_array.rb', line 33 def links @links end |
#page_number ⇒ int
The current page number represented by this collection
17 18 19 |
# File 'lib/nexosis_api/paged_array.rb', line 17 def page_number @page_number end |
#page_size ⇒ int
The total number of items per page
25 26 27 |
# File 'lib/nexosis_api/paged_array.rb', line 25 def page_size @page_size end |
#total_pages ⇒ int
The total number of pages given the current page size and item total
21 22 23 |
# File 'lib/nexosis_api/paged_array.rb', line 21 def total_pages @total_pages end |