Class: SmartPaginate::PaginatingArray
- Inherits:
-
Array
- Object
- Array
- SmartPaginate::PaginatingArray
- Defined in:
- lib/smart_paginate/paginating_array.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_entries ⇒ Object
Returns the value of attribute total_entries.
Instance Method Summary collapse
- #next_page ⇒ Object
- #next_page? ⇒ Boolean
- #paginate(options = {}) ⇒ Object
- #previous_page ⇒ Object
- #previous_page? ⇒ Boolean
- #total_pages ⇒ Object
Instance Attribute Details
#current_page ⇒ Object
Returns the value of attribute current_page.
5 6 7 |
# File 'lib/smart_paginate/paginating_array.rb', line 5 def current_page @current_page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
5 6 7 |
# File 'lib/smart_paginate/paginating_array.rb', line 5 def per_page @per_page end |
#total_entries ⇒ Object
Returns the value of attribute total_entries.
5 6 7 |
# File 'lib/smart_paginate/paginating_array.rb', line 5 def total_entries @total_entries end |
Instance Method Details
#next_page ⇒ Object
31 32 33 |
# File 'lib/smart_paginate/paginating_array.rb', line 31 def next_page current_page + 1 if next_page? end |
#next_page? ⇒ Boolean
23 24 25 |
# File 'lib/smart_paginate/paginating_array.rb', line 23 def next_page? (current_page * per_page) < total_entries end |
#paginate(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/smart_paginate/paginating_array.rb', line 7 def paginate( = {}) page = SmartPaginate::Paginate.new(.fetch(:page), [:per_page]) if page.offset <= length array = self.slice(page.offset, page.per_page) else # out of bounds, just create an empty array array = PaginatingArray.new end array.current_page = page.current_page array.per_page = page.per_page array.total_entries = length array end |
#previous_page ⇒ Object
35 36 37 |
# File 'lib/smart_paginate/paginating_array.rb', line 35 def previous_page current_page - 1 if previous_page? end |
#previous_page? ⇒ Boolean
27 28 29 |
# File 'lib/smart_paginate/paginating_array.rb', line 27 def previous_page? current_page > 1 end |
#total_pages ⇒ Object
39 40 41 |
# File 'lib/smart_paginate/paginating_array.rb', line 39 def total_pages (total_entries / per_page.to_f).ceil end |