Class: ElasticSearchable::Pagination::Kaminari

Inherits:
ElasticSearchable::Paginator show all
Defined in:
lib/elastic_searchable/pagination/kaminari.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ElasticSearchable::Paginator

handler, handler=, #replace

Constructor Details

#initialize(results, page, per_page, total = nil) ⇒ Kaminari

Returns a new instance of Kaminari.



6
7
8
9
10
11
# File 'lib/elastic_searchable/pagination/kaminari.rb', line 6

def initialize(results, page, per_page, total = nil)
  self.page          = page
  self.limit_value   = per_page
  self.total_entries = total if total
  self.replace results
end

Instance Attribute Details

#limit_valueObject Also known as: per_page

Returns the value of attribute limit_value.



4
5
6
# File 'lib/elastic_searchable/pagination/kaminari.rb', line 4

def limit_value
  @limit_value
end

#pageObject Also known as: current_page

Returns the value of attribute page.



4
5
6
# File 'lib/elastic_searchable/pagination/kaminari.rb', line 4

def page
  @page
end

#total_entriesObject

Returns the value of attribute total_entries.



4
5
6
# File 'lib/elastic_searchable/pagination/kaminari.rb', line 4

def total_entries
  @total_entries
end

#total_pagesObject

Returns the value of attribute total_pages.



4
5
6
# File 'lib/elastic_searchable/pagination/kaminari.rb', line 4

def total_pages
  @total_pages
end

Instance Method Details

#first_page?Boolean

First page of the collection ?

Returns:

  • (Boolean)


27
28
29
# File 'lib/elastic_searchable/pagination/kaminari.rb', line 27

def first_page?
  current_page == 1
end

#last_page?Boolean

Last page of the collection?

Returns:

  • (Boolean)


32
33
34
# File 'lib/elastic_searchable/pagination/kaminari.rb', line 32

def last_page?
  current_page >= num_pages
end

#num_pagesObject

Total number of pages



22
23
24
# File 'lib/elastic_searchable/pagination/kaminari.rb', line 22

def num_pages
  (total_count.to_f / per_page).ceil
end

#total_countObject

total item numbers of the original array



17
18
19
# File 'lib/elastic_searchable/pagination/kaminari.rb', line 17

def total_count
  total_entries
end