Class: Que::View::Pagination
- Inherits:
-
Object
- Object
- Que::View::Pagination
- Defined in:
- lib/que/view/pagination.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
Instance Method Summary collapse
- #first_page? ⇒ Boolean
-
#initialize(params: {}) ⇒ Pagination
constructor
A new instance of Pagination.
- #last_page? ⇒ Boolean
- #next_page ⇒ Object
- #next_page? ⇒ Boolean
- #offset ⇒ Object
- #previous_page ⇒ Object
- #previous_page? ⇒ Boolean
- #total_pages ⇒ Object
Constructor Details
#initialize(params: {}) ⇒ Pagination
Returns a new instance of Pagination.
8 9 10 11 12 |
# File 'lib/que/view/pagination.rb', line 8 def initialize(params: {}) @page = params[:page] @count = params[:count] @per_page = params[:per_page] end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
6 7 8 |
# File 'lib/que/view/pagination.rb', line 6 def count @count end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
6 7 8 |
# File 'lib/que/view/pagination.rb', line 6 def page @page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
6 7 8 |
# File 'lib/que/view/pagination.rb', line 6 def per_page @per_page end |
Instance Method Details
#first_page? ⇒ Boolean
40 41 42 |
# File 'lib/que/view/pagination.rb', line 40 def first_page? page == 1 end |
#last_page? ⇒ Boolean
36 37 38 |
# File 'lib/que/view/pagination.rb', line 36 def last_page? page == total_pages end |
#next_page ⇒ Object
20 21 22 |
# File 'lib/que/view/pagination.rb', line 20 def next_page page + 1 unless last_page? end |
#next_page? ⇒ Boolean
24 25 26 |
# File 'lib/que/view/pagination.rb', line 24 def next_page? page < total_pages end |
#offset ⇒ Object
14 15 16 17 18 |
# File 'lib/que/view/pagination.rb', line 14 def offset return 0 if page == 1 per_page * (page.to_i - 1) end |
#previous_page ⇒ Object
28 29 30 |
# File 'lib/que/view/pagination.rb', line 28 def previous_page page - 1 unless first_page? end |
#previous_page? ⇒ Boolean
32 33 34 |
# File 'lib/que/view/pagination.rb', line 32 def previous_page? page > 1 end |
#total_pages ⇒ Object
44 45 46 |
# File 'lib/que/view/pagination.rb', line 44 def total_pages (count / per_page.to_f).ceil end |