Module: RSolr::Ext::Response::Docs::Pageable
- Defined in:
- lib/rsolr-ext/response/docs.rb
Instance Attribute Summary collapse
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#start ⇒ Object
Returns the value of attribute start.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
-
#current_page ⇒ Object
Returns the current page calculated from ‘rows’ and ‘start’ WillPaginate hook.
- #has_next? ⇒ Boolean
- #has_previous? ⇒ Boolean
-
#next_page ⇒ Object
returns the next page number or the last WillPaginate hook.
-
#previous_page ⇒ Object
returns the previous page number or 1 WillPaginate hook.
-
#total_pages ⇒ Object
Calcuates the total pages from ‘numFound’ and ‘rows’ WillPaginate hook.
Instance Attribute Details
#per_page ⇒ Object
Returns the value of attribute per_page.
15 16 17 |
# File 'lib/rsolr-ext/response/docs.rb', line 15 def per_page @per_page end |
#start ⇒ Object
Returns the value of attribute start.
15 16 17 |
# File 'lib/rsolr-ext/response/docs.rb', line 15 def start @start end |
#total ⇒ Object
Returns the value of attribute total.
15 16 17 |
# File 'lib/rsolr-ext/response/docs.rb', line 15 def total @total end |
Instance Method Details
#current_page ⇒ Object
Returns the current page calculated from ‘rows’ and ‘start’ WillPaginate hook
19 20 21 22 23 |
# File 'lib/rsolr-ext/response/docs.rb', line 19 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
43 44 45 |
# File 'lib/rsolr-ext/response/docs.rb', line 43 def has_next? current_page < total_pages end |
#has_previous? ⇒ Boolean
47 48 49 |
# File 'lib/rsolr-ext/response/docs.rb', line 47 def has_previous? current_page > 1 end |
#next_page ⇒ Object
returns the next page number or the last WillPaginate hook
39 40 41 |
# File 'lib/rsolr-ext/response/docs.rb', line 39 def next_page @next_page ||= (current_page == total_pages) ? total_pages : current_page+1 end |
#previous_page ⇒ Object
returns the previous page number or 1 WillPaginate hook
33 34 35 |
# File 'lib/rsolr-ext/response/docs.rb', line 33 def previous_page @previous_page ||= (current_page > 1) ? current_page - 1 : 1 end |
#total_pages ⇒ Object
Calcuates the total pages from ‘numFound’ and ‘rows’ WillPaginate hook
27 28 29 |
# File 'lib/rsolr-ext/response/docs.rb', line 27 def total_pages @total_pages ||= per_page > 0 ? (total / per_page.to_f).ceil : 1 end |