A class representing a single page in a paginator.
- Comparable
[R] | number | |
[R] | paginator | |
[R] | to_i |
Creates a new Page for the given
paginator
with the index number
. If
number
is not in the range of valid page numbers or is not a
number at all, it defaults to 1.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 297 def initialize(paginator, number) @paginator = paginator @number = number.to_i @number = 1 unless @paginator.has_page_number? @number end
Compares two Page objects and returns -1 if the left-hand page comes before the right-hand page, 0 if the pages are equal, and 1 if the left-hand page comes after the right-hand page. Raises ArgumentError if the pages do not belong to the same Paginator object.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 318 def <=>(page) raise ArgumentError unless @paginator == page.paginator @number <=> page.number end
Compares two Page objects and returns true when they represent the same page (i.e., their paginators are the same and they have the same page number).
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 308 def ==(page) return false if page.nil? @paginator == page.paginator and @number == page.number end
Returns true if this page is the first page in the paginator.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 339 def first? self == @paginator.first end
Returns the number of the first item displayed.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 329 def first_item offset + 1 end
Returns true if this page is the last page in the paginator.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 344 def last? self == @paginator.last end
Returns the number of the last item displayed.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 334 def last_item [@paginator.items_per_page * @number, @paginator.item_count].min end
Returns a new Page object representing the page just after this page, or nil if this is the last page.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 356 def next if last? then nil else @paginator[@number + 1] end end
Returns the item offset for the first item in this page.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 324 def offset @paginator.items_per_page * (@number - 1) end
Returns a new Page object representing the page just before this page, or nil if this is the first page.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 350 def previous if first? then nil else @paginator[@number - 1] end end
Returns the limit/offset array for this page.
Source: show
# File rails/actionpack/lib/action_controller/pagination.rb, line 367 def to_sql [@paginator.items_per_page, offset] end