A class representing a single page in a paginator.
- Comparable
| [R] | number | |
| [R] | paginator |
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.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 291
291: def initialize(paginator, number)
292: @paginator = paginator
293: @number = number.to_i
294: @number = 1 unless @paginator.has_page_number? @number
295: 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.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 312
312: def <=>(page)
313: raise ArgumentError unless @paginator == page.paginator
314: @number <=> page.number
315: 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).
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 302
302: def ==(page)
303: return false if page.nil?
304: @paginator == page.paginator and
305: @number == page.number
306: end
Returns true if this page is the first page in the paginator.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 333
333: def first?
334: self == @paginator.first
335: end
Returns the number of the first item displayed.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 323
323: def first_item
324: offset + 1
325: end
Returns true if this page is the last page in the paginator.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 338
338: def last?
339: self == @paginator.last
340: end
Returns the number of the last item displayed.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 328
328: def last_item
329: [@paginator.items_per_page * @number, @paginator.item_count].min
330: end
Returns a new Page object representing the page just after this page, or nil if this is the last page.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 350
350: def next
351: if last? then nil else @paginator[@number + 1] end
352: end
Returns the item offset for the first item in this page.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 318
318: def offset
319: @paginator.items_per_page * (@number - 1)
320: end
Returns a new Page object representing the page just before this page, or nil if this is the first page.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 344
344: def previous
345: if first? then nil else @paginator[@number - 1] end
346: end
Returns the limit/offset array for this page.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 361
361: def to_sql
362: [@paginator.items_per_page, offset]
363: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 356
356: def window(padding=2)
357: Window.new(self, padding)
358: end