Class: Plucky::Pagination::Paginator
- Defined in:
- lib/plucky/pagination/paginator.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#per_page ⇒ Object
(also: #limit)
readonly
Returns the value of attribute per_page.
-
#total_entries ⇒ Object
readonly
Returns the value of attribute total_entries.
Instance Method Summary collapse
-
#initialize(total, page, per_page = nil) ⇒ Paginator
constructor
Public.
-
#next_page ⇒ Object
Public.
-
#out_of_bounds? ⇒ Boolean
Public.
-
#previous_page ⇒ Object
Public.
-
#skip ⇒ Object
(also: #offset)
Public.
-
#total_pages ⇒ Object
Public.
Constructor Details
#initialize(total, page, per_page = nil) ⇒ Paginator
Public
8 9 10 11 12 |
# File 'lib/plucky/pagination/paginator.rb', line 8 def initialize(total, page, per_page=nil) @total_entries = total.to_i @current_page = [page.to_i, 1].max @per_page = (per_page || 25).to_i end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
5 6 7 |
# File 'lib/plucky/pagination/paginator.rb', line 5 def current_page @current_page end |
#per_page ⇒ Object (readonly) Also known as: limit
Returns the value of attribute per_page.
5 6 7 |
# File 'lib/plucky/pagination/paginator.rb', line 5 def per_page @per_page end |
#total_entries ⇒ Object (readonly)
Returns the value of attribute total_entries.
5 6 7 |
# File 'lib/plucky/pagination/paginator.rb', line 5 def total_entries @total_entries end |
Instance Method Details
#next_page ⇒ Object
Public
30 31 32 |
# File 'lib/plucky/pagination/paginator.rb', line 30 def next_page @current_page < total_pages ? (@current_page + 1) : nil end |
#out_of_bounds? ⇒ Boolean
Public
20 21 22 |
# File 'lib/plucky/pagination/paginator.rb', line 20 def out_of_bounds? @current_page > total_pages end |
#previous_page ⇒ Object
Public
25 26 27 |
# File 'lib/plucky/pagination/paginator.rb', line 25 def previous_page @current_page > 1 ? (@current_page - 1) : nil end |
#skip ⇒ Object Also known as: offset
Public
35 36 37 |
# File 'lib/plucky/pagination/paginator.rb', line 35 def skip (@current_page - 1) * @per_page end |
#total_pages ⇒ Object
Public
15 16 17 |
# File 'lib/plucky/pagination/paginator.rb', line 15 def total_pages (@total_entries / @per_page.to_f).ceil end |