Module: Indices::Pagination
- Defined in:
- lib/indices/pagination.rb
Instance Method Summary collapse
- #first_page ⇒ Object
- #last_page ⇒ Object
- #next_page ⇒ Object
- #out_of_bounds? ⇒ Boolean
- #previous_page ⇒ Object
- #total_count ⇒ Object
- #total_pages ⇒ Object
Instance Method Details
#first_page ⇒ Object
16 17 18 |
# File 'lib/indices/pagination.rb', line 16 def first_page 1 end |
#last_page ⇒ Object
20 21 22 |
# File 'lib/indices/pagination.rb', line 20 def last_page total_pages end |
#next_page ⇒ Object
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
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_page ⇒ Object
8 9 10 |
# File 'lib/indices/pagination.rb', line 8 def previous_page @previous_page ||= (current_page > 1 ? (current_page - 1) : nil) end |
#total_count ⇒ Object
28 29 30 |
# File 'lib/indices/pagination.rb', line 28 def total_count @total_count ||= (response['hits']['total'].to_i - padding) end |
#total_pages ⇒ Object
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 |