Class: Storify::Pager
- Inherits:
-
Object
- Object
- Storify::Pager
- Defined in:
- lib/storify/pager.rb
Constant Summary collapse
- MIN_PAGE =
1- MAX_PER_PAGE =
50
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
Instance Method Summary collapse
- #has_pages?(array = []) ⇒ Boolean
-
#initialize(page: 1, per_page: 20, max: 0) ⇒ Pager
constructor
A new instance of Pager.
- #next ⇒ Object
- #prev ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(page: 1, per_page: 20, max: 0) ⇒ Pager
Returns a new instance of Pager.
8 9 10 11 12 |
# File 'lib/storify/pager.rb', line 8 def initialize(page: 1, per_page: 20, max: 0) @max = max.to_i.abs self.page=(page) self.per_page=(per_page) end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
6 7 8 |
# File 'lib/storify/pager.rb', line 6 def max @max end |
#page ⇒ Object
Returns the value of attribute page.
6 7 8 |
# File 'lib/storify/pager.rb', line 6 def page @page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
6 7 8 |
# File 'lib/storify/pager.rb', line 6 def per_page @per_page end |
Instance Method Details
#has_pages?(array = []) ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/storify/pager.rb', line 32 def has_pages?(array = []) return false unless array.is_a?(Array) return false if (@page > @max && @max != 0) array.length != 0 end |
#next ⇒ Object
18 19 20 21 |
# File 'lib/storify/pager.rb', line 18 def next self.page=(@page + 1) self end |
#prev ⇒ Object
23 24 25 26 |
# File 'lib/storify/pager.rb', line 23 def prev self.page=(@page - 1) self end |
#to_hash ⇒ Object
28 29 30 |
# File 'lib/storify/pager.rb', line 28 def to_hash {:page => @page, :per_page => @per_page} end |