Class: ThinkingSphinx::Masks::PaginationMask

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

Instance Method Summary collapse

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


16
17
18
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 16

def last_page?
  next_page.nil?
end

#next_pageObject



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

Returns:

  • (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.options[: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.options[:limit] = limit
  search
end

#previous_pageObject 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_entriesObject Also known as: total_count, count



44
45
46
# File 'lib/thinking_sphinx/masks/pagination_mask.rb', line 44

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

#total_pagesObject 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.meta['total'].nil?

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