Sha256: 76ad3dac13e5e2a96a9dc52a0737ee9123851509f6ab99be7d565de0eb572673
Contents?: true
Size: 759 Bytes
Versions: 4
Compression:
Stored size: 759 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 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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
paginate-0.1.3 | lib/paginate/base.rb |
paginate-0.1.2 | lib/paginate/base.rb |
paginate-0.1.1 | lib/paginate/base.rb |
paginate-0.1.0 | lib/paginate/base.rb |