Module: Indices::Pagination

Defined in:
lib/indices/pagination.rb

Instance Method Summary collapse

Instance Method Details

#first_pageObject



16
17
18
# File 'lib/indices/pagination.rb', line 16

def first_page
  1
end

#last_pageObject



20
21
22
# File 'lib/indices/pagination.rb', line 20

def last_page
  total_pages
end

#next_pageObject



12
13
14
# File 'lib/indices/pagination.rb', line 12

def next_page
  @next_page ||= (current_page < total_pages ? (current_page + 1) : nil)
end

#out_of_bounds?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/indices/pagination.rb', line 24

def out_of_bounds?
  @out_of_bounds ||= (current_page > total_pages || current_page < first_page)
end

#previous_pageObject



8
9
10
# File 'lib/indices/pagination.rb', line 8

def previous_page
  @previous_page ||= (current_page > 1 ? (current_page - 1) : nil)
end

#total_countObject



28
29
30
# File 'lib/indices/pagination.rb', line 28

def total_count
  @total_count ||= (response['hits']['total'].to_i - padding)
end

#total_pagesObject



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

def total_pages
  @total_pages ||= [(total_count.to_f / page_length).ceil, 1].max
end