Class: RSolrExt::Response::Select::Paginator

Inherits:
Object
  • Object
show all
Defined in:
lib/rsolr_ext/response/select.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#startObject (readonly)

Returns the value of attribute start.



140
141
142
# File 'lib/rsolr_ext/response/select.rb', line 140

def start
  @start
end

#totalObject (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_pageObject

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_pageObject

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_pageObject

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_pagesObject

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