Class: BootstrapPager::PaginatableArray

Inherits:
Array
  • Object
show all
Includes:
ConfigurationMethods::ClassMethods
Defined in:
lib/bootstrap_pager/models/array_extension.rb

Overview

Kind of Array that can paginate

Instance Method Summary collapse

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 = [], options = {})
  @_original_array, @_limit_value, @_offset_value, @_total_count, @_padding = original_array, (options[:limit] || default_per_page).to_i, options[:offset].to_i, options[:total_count], options[:padding].to_i

  if options[:limit] && options[:offset]
    extend BootstrapPager::PageScopeMethods
  end

  if options[: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_countObject

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