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 284
284: def initialize(paginator, number)
285: @paginator = paginator
286: @number = number.to_i
287: @number = 1 unless @paginator.has_page_number? @number
288: 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 305
305: def <=>(page)
306: raise ArgumentError unless @paginator == page.paginator
307: @number <=> page.number
308: 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 295
295: def ==(page)
296: return false if page.nil?
297: @paginator == page.paginator and
298: @number == page.number
299: 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 326
326: def first?
327: self == @paginator.first
328: end
Returns the number of the first item displayed.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 316
316: def first_item
317: offset + 1
318: 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 331
331: def last?
332: self == @paginator.last
333: end
Returns the number of the last item displayed.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 321
321: def last_item
322: [@paginator.items_per_page * @number, @paginator.item_count].min
323: 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 343
343: def next
344: if last? then nil else @paginator[@number + 1] end
345: end
Returns the item offset for the first item in this page.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 311
311: def offset
312: @paginator.items_per_page * (@number - 1)
313: 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 337
337: def previous
338: if first? then nil else @paginator[@number - 1] end
339: end
Returns the limit/offset array for this page.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 354
354: def to_sql
355: [@paginator.items_per_page, offset]
356: end
Returns a new Window object for this page with the specified padding.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/pagination.rb, line 349
349: def window(padding=2)
350: Window.new(self, padding)
351: end