Module: PaginateSimple
- Defined in:
- lib/paginate-simple.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
Returns the value of attribute current_page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
- #config(args = {}) ⇒ Object
- #first_page ⇒ Object
- #has_next_page? ⇒ Boolean
- #has_previous_page? ⇒ Boolean
- #last_page ⇒ Object
- #next_page ⇒ Object
- #num_of_pages ⇒ Object
- #offset ⇒ Object
- #pages ⇒ Object
- #previous_page ⇒ Object
Instance Attribute Details
#current_page ⇒ Object
Returns the value of attribute current_page.
2 3 4 |
# File 'lib/paginate-simple.rb', line 2 def current_page @current_page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
2 3 4 |
# File 'lib/paginate-simple.rb', line 2 def per_page @per_page end |
#total ⇒ Object
Returns the value of attribute total.
2 3 4 |
# File 'lib/paginate-simple.rb', line 2 def total @total end |
Instance Method Details
#config(args = {}) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/paginate-simple.rb', line 4 def config(args = {}) args = { :per_page => 10 }.merge(args) self.current_page = args[:page] self.total = args[:total] @per_page = args[:per_page] end |
#first_page ⇒ Object
23 24 25 |
# File 'lib/paginate-simple.rb', line 23 def first_page 1 end |
#has_next_page? ⇒ Boolean
15 16 17 |
# File 'lib/paginate-simple.rb', line 15 def has_next_page? current_page < num_of_pages end |
#has_previous_page? ⇒ Boolean
19 20 21 |
# File 'lib/paginate-simple.rb', line 19 def has_previous_page? current_page > first_page end |
#last_page ⇒ Object
27 28 29 |
# File 'lib/paginate-simple.rb', line 27 def last_page num_of_pages end |
#next_page ⇒ Object
39 40 41 |
# File 'lib/paginate-simple.rb', line 39 def next_page has_next_page? ? current_page + 1 : nil end |
#num_of_pages ⇒ Object
11 12 13 |
# File 'lib/paginate-simple.rb', line 11 def num_of_pages (total.to_f / per_page.to_f).ceil end |
#offset ⇒ Object
35 36 37 |
# File 'lib/paginate-simple.rb', line 35 def offset (current_page - 1) * per_page end |
#pages ⇒ Object
31 32 33 |
# File 'lib/paginate-simple.rb', line 31 def pages (first_page..last_page).to_a end |
#previous_page ⇒ Object
43 44 45 |
# File 'lib/paginate-simple.rb', line 43 def previous_page has_previous_page? ? current_page - 1 : nil end |