Module: RSolr::Ext::Response::Docs::Pageable

Defined in:
lib/rsolr-ext/response/docs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#per_pageObject

Returns the value of attribute per_page.



5
6
7
# File 'lib/rsolr-ext/response/docs.rb', line 5

def per_page
  @per_page
end

#startObject

Returns the value of attribute start.



5
6
7
# File 'lib/rsolr-ext/response/docs.rb', line 5

def start
  @start
end

#totalObject

Returns the value of attribute total.



5
6
7
# File 'lib/rsolr-ext/response/docs.rb', line 5

def total
  @total
end

Instance Method Details

#current_pageObject

Returns the current page calculated from ‘rows’ and ‘start’ WillPaginate hook



9
10
11
12
13
# File 'lib/rsolr-ext/response/docs.rb', line 9

def current_page
  return 1 if start < 1
  per_page_normalized = per_page < 1 ? 1 : per_page
  @current_page ||= (start / per_page_normalized).ceil + 1
end

#has_next?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rsolr-ext/response/docs.rb', line 33

def has_next?
  current_page < total_pages
end

#has_previous?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/rsolr-ext/response/docs.rb', line 37

def has_previous?
  current_page > 1
end

#next_pageObject

returns the next page number or the last WillPaginate hook



29
30
31
# File 'lib/rsolr-ext/response/docs.rb', line 29

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

#previous_pageObject

returns the previous page number or 1 WillPaginate hook



23
24
25
# File 'lib/rsolr-ext/response/docs.rb', line 23

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

#total_pagesObject

Calcuates the total pages from ‘numFound’ and ‘rows’ WillPaginate hook



17
18
19
# File 'lib/rsolr-ext/response/docs.rb', line 17

def total_pages
  @total_pages ||= per_page > 0 ? (total / per_page.to_f).ceil : 1
end