Class: ThinkingSphinx::Masks::PaginationMask

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/masks/pagination_mask.rb

Instance Method Summary (collapse)

Constructor Details

- (PaginationMask) initialize(search)



2
3
4
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 2

def initialize(search)
  @search = search
end

Instance Method Details

- (Boolean) can_handle?(method)



6
7
8
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 6

def can_handle?(method)
  public_methods(false).include?(method)
end

- (Boolean) first_page?



10
11
12
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 10

def first_page?
  search.current_page == 1
end

- (Boolean) last_page?



14
15
16
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 14

def last_page?
  next_page.nil?
end

- (Object) next_page



18
19
20
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 18

def next_page
  search.current_page >= total_pages ? nil : search.current_page + 1
end

- (Boolean) next_page?



22
23
24
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 22

def next_page?
  !next_page.nil?
end

- (Object) page(number)



26
27
28
29
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 26

def page(number)
  search.options[:page] = number
  search
end

- (Object) per(limit)



31
32
33
34
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 31

def per(limit)
  search.options[:limit] = limit
  search
end

- (Object) previous_page



36
37
38
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 36

def previous_page
  search.current_page == 1 ? nil : search.current_page - 1
end

- (Object) total_entries Also known as: total_count, count



40
41
42
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 40

def total_entries
  search.meta['total_found'].to_i
end

- (Object) total_pages Also known as: page_count, num_pages



47
48
49
50
51
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 47

def total_pages
  return 0 if search.meta['total'].nil?

  @total_pages ||= (search.meta['total'].to_i / search.per_page.to_f).ceil
end