Class: Alula::Pagination
- Inherits:
-
Object
- Object
- Alula::Pagination
- Defined in:
- lib/alula/pagination.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #has_next? ⇒ Boolean
- #has_prev? ⇒ Boolean
-
#initialize(meta_page_obj) ⇒ Pagination
constructor
A new instance of Pagination.
- #page_count ⇒ Object
Constructor Details
#initialize(meta_page_obj) ⇒ Pagination
Returns a new instance of Pagination.
5 6 7 8 9 |
# File 'lib/alula/pagination.rb', line 5 def initialize() @total = ['total'] @number = ['number'] @size = ['size'] end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
3 4 5 |
# File 'lib/alula/pagination.rb', line 3 def number @number end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
3 4 5 |
# File 'lib/alula/pagination.rb', line 3 def size @size end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/alula/pagination.rb', line 3 def total @total end |
Instance Method Details
#has_next? ⇒ Boolean
11 12 13 |
# File 'lib/alula/pagination.rb', line 11 def has_next? number < page_count end |
#has_prev? ⇒ Boolean
15 16 17 |
# File 'lib/alula/pagination.rb', line 15 def has_prev? number > 1 end |
#page_count ⇒ Object
19 20 21 22 23 |
# File 'lib/alula/pagination.rb', line 19 def page_count (total.to_f / size.to_f).ceil rescue ZeroDivisionError 0 end |