Module: ToughGuy::Query::PaginationMethods

Defined in:
lib/toughguy/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



168
169
170
# File 'lib/toughguy/query.rb', line 168

def current_page
  @current_page
end

#per_pageObject

Returns the value of attribute per_page.



168
169
170
# File 'lib/toughguy/query.rb', line 168

def per_page
  @per_page
end

#total_countObject

Returns the value of attribute total_count.



168
169
170
# File 'lib/toughguy/query.rb', line 168

def total_count
  @total_count
end

#total_pagesObject

Returns the value of attribute total_pages.



168
169
170
# File 'lib/toughguy/query.rb', line 168

def total_pages
  @total_pages
end

Instance Method Details

#current_page_record_rangeObject

Returns the record range for the current page



186
187
188
189
190
191
192
193
# File 'lib/toughguy/query.rb', line 186

def current_page_record_range
  return (0..0) if @current_page > @total_pages
    
  a = 1 + (@current_page - 1) * @per_page
  b = a + @per_page - 1
  b = @total_count if b > @total_count
  a..b
end

#next_pageObject

Returns the next page number or nil if the current page is the last page



176
177
178
# File 'lib/toughguy/query.rb', line 176

def next_page
  @current_page < @total_pages ? (@current_page + 1) : nil
end

#page_rangeObject

Returns the page range



181
182
183
# File 'lib/toughguy/query.rb', line 181

def page_range
  1..@total_pages
end

#prev_pageObject

Returns the previous page number or nil if the current page is the first



171
172
173
# File 'lib/toughguy/query.rb', line 171

def prev_page
  @current_page > 1 ? (@current_page - 1) : nil
end