Class: Pageboy::PageTurner::Array
- Defined in:
- lib/pageboy/page_turner/array.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#first, #first_page_id, #initialize, #with_merged_options
Constructor Details
This class inherits a constructor from Pageboy::PageTurner::Base
Instance Method Details
#page(page_id, opts = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pageboy/page_turner/array.rb', line 7 def page(page_id, opts={}) (opts) do |o| per_page = Integer(o[:per_page]) i = Integer(page_id) max_page = (resource.size.to_f / per_page).ceil prev_page_id = i - 1 < 1 ? nil : i - 1 next_page_id = i + 1 > max_page ? nil : i + 1 first_item_index = (i-1) * per_page last_item_index = i * per_page - 1 slice = resource[first_item_index..last_item_index] Page.new(self, slice, prev_page_id, next_page_id) end end |