Class: GearedPagination::Ratios

Inherits:
Object
  • Object
show all
Defined in:
lib/geared_pagination/ratios.rb

Constant Summary collapse

DEFAULTS =
[ 15, 30, 50, 100 ]

Instance Method Summary collapse

Constructor Details

#initialize(ratios = nil) ⇒ Ratios

Returns a new instance of Ratios.



5
6
7
# File 'lib/geared_pagination/ratios.rb', line 5

def initialize(ratios = nil)
  @ratios = Array(ratios || DEFAULTS).map(&:to_i)
end

Instance Method Details

#[](page_number) ⇒ Object



9
10
11
# File 'lib/geared_pagination/ratios.rb', line 9

def [](page_number)
  @ratios[page_number - 1] || fixed
end

#cache_keyObject



13
14
15
# File 'lib/geared_pagination/ratios.rb', line 13

def cache_key
  @ratios.join('-')
end

#fixedObject



21
22
23
# File 'lib/geared_pagination/ratios.rb', line 21

def fixed
  @ratios.last
end

#sizeObject



17
18
19
# File 'lib/geared_pagination/ratios.rb', line 17

def size
  @ratios.size
end