Sha256: 2bf9cf3009db5dc479f472805a48077b1d02920588c757206afaa270a4e352c8
Contents?: true
Size: 524 Bytes
Versions: 5
Compression:
Stored size: 524 Bytes
Contents
class Paginator include Enumerable attr_reader :page, :size def initialize(collection, options={}) @collection = collection @page = options[:page] ? options[:page].to_i : 1 @size = options[:size] ? options[:size].to_i : 10 end def each(&block) from = size * (page - 1) (@collection.slice(from, size) || []).each(&block) end def total @collection.count end def pages (total / size.to_f).ceil end def first? page == 1 end def last? page == pages end end
Version data entries
5 entries across 5 versions & 1 rubygems