Class: BootstrapPager::PaginatableArray
- Inherits:
-
Array
- Object
- Array
- BootstrapPager::PaginatableArray
- Includes:
- ConfigurationMethods::ClassMethods
- Defined in:
- lib/bootstrap_pager/models/array_extension.rb
Overview
Kind of Array that can paginate
Instance Method Summary collapse
-
#initialize(original_array = [], options = {}) ⇒ PaginatableArray
constructor
Options *
:limit
- limit *:offset
- offset *:total_count
- total_count. -
#limit(num) ⇒ Object
returns another chunk of the original array.
-
#offset(num) ⇒ Object
returns another chunk of the original array.
-
#total_count ⇒ Object
total item numbers of the original array.
Methods included from ConfigurationMethods::ClassMethods
#default_per_page, #max_pages, #max_pages_per, #max_paginates_per, #max_per_page, #paginates_per
Constructor Details
#initialize(original_array = [], options = {}) ⇒ PaginatableArray
Options
-
:limit
- limit -
:offset
- offset -
:total_count
- total_count
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bootstrap_pager/models/array_extension.rb', line 13 def initialize(original_array = [], = {}) @_original_array, @_limit_value, @_offset_value, @_total_count, @_padding = original_array, ([:limit] || default_per_page).to_i, [:offset].to_i, [:total_count], [:padding].to_i if [:limit] && [:offset] extend BootstrapPager::PageScopeMethods end if [:total_count] super original_array else super(original_array[@_offset_value, @_limit_value] || []) end end |
Instance Method Details
#limit(num) ⇒ Object
returns another chunk of the original array
35 36 37 |
# File 'lib/bootstrap_pager/models/array_extension.rb', line 35 def limit(num) self.class.new @_original_array, :limit => num, :offset => @_offset_value, :total_count => @_total_count, :padding => @_padding end |
#offset(num) ⇒ Object
returns another chunk of the original array
45 46 47 |
# File 'lib/bootstrap_pager/models/array_extension.rb', line 45 def offset(num) self.class.new @_original_array, :limit => @_limit_value, :offset => num, :total_count => @_total_count, :padding => @_padding end |
#total_count ⇒ Object
total item numbers of the original array
40 41 42 |
# File 'lib/bootstrap_pager/models/array_extension.rb', line 40 def total_count @_total_count || @_original_array.count end |