Class: Elasticord::Client::ArrayWithMetaData

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/elasticord/client/array_with_meta_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_default, per_page_default) ⇒ ArrayWithMetaData

Returns a new instance of ArrayWithMetaData.



6
7
8
9
10
11
12
13
14
# File 'lib/elasticord/client/array_with_meta_data.rb', line 6

def initialize(page_default, per_page_default)
  @internal_array = []

  @per_page = per_page_default
  @current_page = page_default
  @total_results = 0

  super(@internal_array)
end

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



4
5
6
# File 'lib/elasticord/client/array_with_meta_data.rb', line 4

def current_page
  @current_page
end

#per_pageObject

Returns the value of attribute per_page.



4
5
6
# File 'lib/elasticord/client/array_with_meta_data.rb', line 4

def per_page
  @per_page
end

#total_resultsObject Also known as: total_count

Returns the value of attribute total_results.



4
5
6
# File 'lib/elasticord/client/array_with_meta_data.rb', line 4

def total_results
  @total_results
end

Instance Method Details

#fromObject



26
27
28
# File 'lib/elasticord/client/array_with_meta_data.rb', line 26

def from
  (current_page - 1) * size
end

#sizeObject



22
23
24
# File 'lib/elasticord/client/array_with_meta_data.rb', line 22

def size
  per_page
end

#total_pagesObject



18
19
20
# File 'lib/elasticord/client/array_with_meta_data.rb', line 18

def total_pages
  (total_results / per_page.to_f).ceil
end