Class: NexosisApi::PagedArray

Inherits:
Array
  • Object
show all
Defined in:
lib/nexosis_api/paged_array.rb

Overview

Generic list base class for list responses

Since:

  • 1.4.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paged_response, item_array = []) ⇒ PagedArray

Returns a new instance of PagedArray.

Since:

  • 1.4.0



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_totalint

The total number of items available on the server for this collection

Returns:

  • (int)

Since:

  • 1.4.0



29
30
31
# File 'lib/nexosis_api/paged_array.rb', line 29

def item_total
  @item_total
end

paging links to first, last pages

Returns:

Since:

  • 1.4.0



33
34
35
# File 'lib/nexosis_api/paged_array.rb', line 33

def links
  @links
end

#page_numberint

The current page number represented by this collection

Returns:

  • (int)

Since:

  • 1.4.0



17
18
19
# File 'lib/nexosis_api/paged_array.rb', line 17

def page_number
  @page_number
end

#page_sizeint

The total number of items per page

Returns:

  • (int)

Since:

  • 1.4.0



25
26
27
# File 'lib/nexosis_api/paged_array.rb', line 25

def page_size
  @page_size
end

#total_pagesint

The total number of pages given the current page size and item total

Returns:

  • (int)

Since:

  • 1.4.0



21
22
23
# File 'lib/nexosis_api/paged_array.rb', line 21

def total_pages
  @total_pages
end