Sha256: 34f83862bcf912811f466121ee156c059c45defc78d63308f35cb3cd8ab77fe0
Contents?: true
Size: 765 Bytes
Versions: 3
Compression:
Stored size: 765 Bytes
Contents
module Paginate class Base attr_accessor :options def initialize(options = {}) if options.kind_of?(Hash) @options = options else @options = {:page => options.to_i} end @options.reverse_merge!(Paginate::Config.to_hash) end def collection_size @collection_size ||= options[:collection].size end def next_page? collection_size > options[:size] end def previous_page? options[:page] > 1 end def page [1, options.fetch(:page, 1).to_i].max end def offset (page - 1) * (limit - 1) end def limit [options[:size], 10].compact.first.to_i + 1 end def to_options { :limit => limit, :offset => offset } end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
paginate-2.0.0 | lib/paginate/base.rb |
paginate-1.0.1 | lib/paginate/base.rb |
paginate-1.0.0 | lib/paginate/base.rb |