class MarkMapper::Pagination::Paginator
Attributes
current_page[R]
limit[R]
per_page[R]
total_entries[R]
Public Class Methods
new(total, page, per_page=nil)
click to toggle source
Public
# File lib/mark_mapper/pagination/paginator.rb, line 8 def initialize(total, page, per_page=nil) @total_entries = total.to_i @current_page = [page.to_i, 1].max @per_page = (per_page || 25).to_i end
Public Instance Methods
next_page()
click to toggle source
Public
# File lib/mark_mapper/pagination/paginator.rb, line 30 def next_page @current_page < total_pages ? (@current_page + 1) : nil end
out_of_bounds?()
click to toggle source
Public
# File lib/mark_mapper/pagination/paginator.rb, line 20 def out_of_bounds? @current_page > total_pages end
previous_page()
click to toggle source
Public
# File lib/mark_mapper/pagination/paginator.rb, line 25 def previous_page @current_page > 1 ? (@current_page - 1) : nil end
skip()
click to toggle source
Public
# File lib/mark_mapper/pagination/paginator.rb, line 35 def skip (@current_page - 1) * @per_page end
Also aliased as: offset
total_pages()
click to toggle source
Public
# File lib/mark_mapper/pagination/paginator.rb, line 15 def total_pages (@total_entries / @per_page.to_f).ceil end