Class: ThinkingSphinx::Masks::PaginationMask
- Inherits:
-
Object
- Object
- ThinkingSphinx::Masks::PaginationMask
- Defined in:
- lib/thinking_sphinx/masks/pagination_mask.rb
Instance Method Summary collapse
- #can_handle?(method) ⇒ Boolean
- #first_page? ⇒ Boolean
-
#initialize(search) ⇒ PaginationMask
constructor
A new instance of PaginationMask.
- #last_page? ⇒ Boolean
- #next_page ⇒ Object
- #next_page? ⇒ Boolean
- #page(number) ⇒ Object
- #per(limit) ⇒ Object
- #previous_page ⇒ Object (also: #prev_page)
- #total_entries ⇒ Object (also: #total_count, #count)
- #total_pages ⇒ Object (also: #page_count, #num_pages)
Constructor Details
#initialize(search) ⇒ PaginationMask
Returns a new instance of PaginationMask.
4 5 6 |
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 4 def initialize(search) @search = search end |
Instance Method Details
#can_handle?(method) ⇒ Boolean
8 9 10 |
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 8 def can_handle?(method) public_methods(false).include?(method) end |
#first_page? ⇒ Boolean
12 13 14 |
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 12 def first_page? search.current_page == 1 end |
#last_page? ⇒ Boolean
16 17 18 |
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 16 def last_page? next_page.nil? end |
#next_page ⇒ Object
20 21 22 |
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 20 def next_page search.current_page >= total_pages ? nil : search.current_page + 1 end |
#next_page? ⇒ Boolean
24 25 26 |
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 24 def next_page? !next_page.nil? end |
#page(number) ⇒ Object
28 29 30 31 |
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 28 def page(number) search.[:page] = number search end |
#per(limit) ⇒ Object
33 34 35 36 |
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 33 def per(limit) search.[:limit] = limit search end |
#previous_page ⇒ Object Also known as: prev_page
38 39 40 |
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 38 def previous_page search.current_page == 1 ? nil : search.current_page - 1 end |
#total_entries ⇒ Object Also known as: total_count, count
44 45 46 |
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 44 def total_entries search.['total_found'].to_i end |
#total_pages ⇒ Object Also known as: page_count, num_pages
51 52 53 54 55 |
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 51 def total_pages return 0 if search.['total'].nil? @total_pages ||= (search.['total'].to_i / search.per_page.to_f).ceil end |