Class: RSolr::Response::PaginatedDocSet
- Inherits:
-
Array
- Object
- Array
- RSolr::Response::PaginatedDocSet
- Defined in:
- lib/rsolr/response.rb
Overview
A response module which gets mixed into the solr [“response”] array.
Instance Attribute Summary collapse
-
#page_start ⇒ Object
(also: #start)
Returns the value of attribute page_start.
-
#page_total ⇒ Object
(also: #total)
Returns the value of attribute page_total.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
Instance Method Summary collapse
-
#current_page ⇒ Object
Returns the current page calculated from ‘rows’ and ‘start’.
- #has_next? ⇒ Boolean
- #has_previous? ⇒ Boolean
-
#next_page ⇒ Object
returns the next page number or the last.
-
#previous_page ⇒ Object
returns the previous page number or 1.
-
#total_pages ⇒ Object
Calcuates the total pages from ‘numFound’ and ‘rows’.
Instance Attribute Details
#page_start ⇒ Object Also known as: start
Returns the value of attribute page_start.
46 47 48 |
# File 'lib/rsolr/response.rb', line 46 def page_start @page_start end |
#page_total ⇒ Object Also known as: total
Returns the value of attribute page_total.
46 47 48 |
# File 'lib/rsolr/response.rb', line 46 def page_total @page_total end |
#per_page ⇒ Object
Returns the value of attribute per_page.
46 47 48 |
# File 'lib/rsolr/response.rb', line 46 def per_page @per_page end |
Instance Method Details
#current_page ⇒ Object
Returns the current page calculated from ‘rows’ and ‘start’
55 56 57 58 59 |
# File 'lib/rsolr/response.rb', line 55 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
76 77 78 |
# File 'lib/rsolr/response.rb', line 76 def has_next? current_page < total_pages end |
#has_previous? ⇒ Boolean
80 81 82 |
# File 'lib/rsolr/response.rb', line 80 def has_previous? current_page > 1 end |
#next_page ⇒ Object
returns the next page number or the last
72 73 74 |
# File 'lib/rsolr/response.rb', line 72 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
67 68 69 |
# File 'lib/rsolr/response.rb', line 67 def previous_page @previous_page ||= (current_page > 1) ? current_page - 1 : 1 end |
#total_pages ⇒ Object
Calcuates the total pages from ‘numFound’ and ‘rows’
62 63 64 |
# File 'lib/rsolr/response.rb', line 62 def total_pages @total_pages ||= per_page > 0 ? (total / per_page.to_f).ceil : 1 end |