class SimplyPaginate::Page
Attributes
collection[R]
index[R]
size[R]
Public Class Methods
new(page, collection, size = Paginator.per_page)
click to toggle source
# File lib/simply_paginate/page.rb, line 5 def initialize(page, collection, size = Paginator.per_page) @index = page @collection = collection @size = size @move_page = lambda do |number| new_index = index + number Page.new(new_index, collection, size) unless (new_index <= 0) || (new_index > (collection.count.to_f / size.to_f).ceil) end end
Public Instance Methods
==(other)
click to toggle source
# File lib/simply_paginate/page.rb, line 31 def ==(other) return false unless other.respond_to?(:index) && other.respond_to?(:elements) (index == other.index) && (elements == other.elements) end
elements()
click to toggle source
# File lib/simply_paginate/page.rb, line 24 def elements first = (@index - 1) * @size last = first + size - 1 collection[first..last] end
next()
click to toggle source
# File lib/simply_paginate/page.rb, line 16 def next @move_page.call(1) end
previous()
click to toggle source
# File lib/simply_paginate/page.rb, line 20 def previous @move_page.call(-1) end