Class: Paginate::Base
- Inherits:
-
Object
- Object
- Paginate::Base
- Defined in:
- lib/paginate/base.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #collection_size ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #limit ⇒ Object
- #next_page? ⇒ Boolean
- #offset ⇒ Object
- #page ⇒ Object
- #previous_page? ⇒ Boolean
- #to_options ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/paginate/base.rb', line 3 def @options end |
Instance Method Details
#collection_size ⇒ Object
15 16 17 |
# File 'lib/paginate/base.rb', line 15 def collection_size @collection_size ||= [:collection].size end |
#limit ⇒ Object
35 36 37 |
# File 'lib/paginate/base.rb', line 35 def limit [[:size], 10].compact.first.to_i + 1 end |
#next_page? ⇒ Boolean
19 20 21 |
# File 'lib/paginate/base.rb', line 19 def next_page? collection_size > [:size] end |
#offset ⇒ Object
31 32 33 |
# File 'lib/paginate/base.rb', line 31 def offset (page - 1) * (limit - 1) end |
#page ⇒ Object
27 28 29 |
# File 'lib/paginate/base.rb', line 27 def page [1, .fetch(:page, 1).to_i].max end |
#previous_page? ⇒ Boolean
23 24 25 |
# File 'lib/paginate/base.rb', line 23 def previous_page? [:page] > 1 end |
#to_options ⇒ Object
39 40 41 |
# File 'lib/paginate/base.rb', line 39 def { :limit => limit, :offset => offset } end |