Class: Storify::Pager

Inherits:
Object
  • Object
show all
Defined in:
lib/storify/pager.rb

Constant Summary collapse

MIN_PAGE =
1
MAX_PER_PAGE =
50

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page: 1, per_page: 20, max: 0) ⇒ Pager

Returns a new instance of Pager.



8
9
10
11
12
# File 'lib/storify/pager.rb', line 8

def initialize(page: 1, per_page: 20, max: 0)
  @max = max.to_i.abs
  self.page=(page)
  self.per_page=(per_page)
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



6
7
8
# File 'lib/storify/pager.rb', line 6

def max
  @max
end

#pageObject

Returns the value of attribute page.



6
7
8
# File 'lib/storify/pager.rb', line 6

def page
  @page
end

#per_pageObject

Returns the value of attribute per_page.



6
7
8
# File 'lib/storify/pager.rb', line 6

def per_page
  @per_page
end

Instance Method Details

#has_pages?(array = []) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
# File 'lib/storify/pager.rb', line 32

def has_pages?(array = [])
  return false unless array.is_a?(Array)
  return false if (@page > @max && @max != 0)

  array.length != 0
end

#nextObject



18
19
20
21
# File 'lib/storify/pager.rb', line 18

def next
  self.page=(@page + 1)
  self
end

#prevObject



23
24
25
26
# File 'lib/storify/pager.rb', line 23

def prev
  self.page=(@page - 1)
  self
end

#to_hashObject



28
29
30
# File 'lib/storify/pager.rb', line 28

def to_hash
  {:page => @page, :per_page => @per_page}
end