Class: RailsPulse::Paginator
- Inherits:
-
Object
- Object
- RailsPulse::Paginator
- Defined in:
- lib/rails_pulse/paginator.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
-
#initialize(count:, page:, limit:) ⇒ Paginator
constructor
A new instance of Paginator.
- #last ⇒ Object
- #next ⇒ Object
- #previous ⇒ Object
Constructor Details
#initialize(count:, page:, limit:) ⇒ Paginator
Returns a new instance of Paginator.
5 6 7 8 9 |
# File 'lib/rails_pulse/paginator.rb', line 5 def initialize(count:, page:, limit:) @count = count @limit = limit @page = page.clamp(1, last) end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
3 4 5 |
# File 'lib/rails_pulse/paginator.rb', line 3 def count @count end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
3 4 5 |
# File 'lib/rails_pulse/paginator.rb', line 3 def limit @limit end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
3 4 5 |
# File 'lib/rails_pulse/paginator.rb', line 3 def page @page end |
Instance Method Details
#last ⇒ Object
11 12 13 |
# File 'lib/rails_pulse/paginator.rb', line 11 def last [ (count.to_f / limit).ceil, 1 ].max end |
#next ⇒ Object
19 20 21 |
# File 'lib/rails_pulse/paginator.rb', line 19 def next page < last ? page + 1 : nil end |
#previous ⇒ Object
15 16 17 |
# File 'lib/rails_pulse/paginator.rb', line 15 def previous page > 1 ? page - 1 : nil end |