Class: RSolrExt::Response::Select::Paginator
- Inherits:
-
Object
- Object
- RSolrExt::Response::Select::Paginator
- Defined in:
- lib/rsolr_ext/response/select.rb
Instance Attribute Summary collapse
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#current_page ⇒ Object
Returns the current page calculated from ‘rows’ and ‘start’ WillPaginate hook.
-
#initialize(start, per_page, total) ⇒ Paginator
constructor
A new instance of Paginator.
-
#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.
Constructor Details
#initialize(start, per_page, total) ⇒ Paginator
Returns a new instance of Paginator.
142 143 144 145 146 |
# File 'lib/rsolr_ext/response/select.rb', line 142 def initialize(start, per_page, total) @start = start.to_s.to_i @per_page = per_page.to_s.to_i @total = total.to_s.to_i end |
Instance Attribute Details
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
140 141 142 |
# File 'lib/rsolr_ext/response/select.rb', line 140 def per_page @per_page end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
140 141 142 |
# File 'lib/rsolr_ext/response/select.rb', line 140 def start @start end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
140 141 142 |
# File 'lib/rsolr_ext/response/select.rb', line 140 def total @total end |
Instance Method Details
#current_page ⇒ Object
Returns the current page calculated from ‘rows’ and ‘start’ WillPaginate hook
150 151 152 153 |
# File 'lib/rsolr_ext/response/select.rb', line 150 def current_page return 1 if start < 1 @current_page ||= (start / per_page).ceil + 1 end |
#next_page ⇒ Object
returns the next page number or the last WillPaginate hook
169 170 171 |
# File 'lib/rsolr_ext/response/select.rb', line 169 def next_page @next_page ||= (current_page < total_pages) ? current_page + 1 : total_pages end |
#previous_page ⇒ Object
returns the previous page number or 1 WillPaginate hook
163 164 165 |
# File 'lib/rsolr_ext/response/select.rb', line 163 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
157 158 159 |
# File 'lib/rsolr_ext/response/select.rb', line 157 def total_pages @total_pages ||= per_page > 0 ? (total / per_page.to_f).ceil : 1 end |