Module: PaginateSimple

Defined in:
lib/paginate-simple.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



2
3
4
# File 'lib/paginate-simple.rb', line 2

def current_page
  @current_page
end

#per_pageObject

Returns the value of attribute per_page.



2
3
4
# File 'lib/paginate-simple.rb', line 2

def per_page
  @per_page
end

#totalObject

Returns the value of attribute total.



2
3
4
# File 'lib/paginate-simple.rb', line 2

def total
  @total
end

Instance Method Details

#config(args = {}) ⇒ Object



4
5
6
7
8
9
# File 'lib/paginate-simple.rb', line 4

def config(args = {})
  args = { :per_page => 10 }.merge(args)
  self.current_page = args[:page]
  self.total = args[:total]
  @per_page = args[:per_page] 
end

#first_pageObject



23
24
25
# File 'lib/paginate-simple.rb', line 23

def first_page
  1
end

#has_next_page?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/paginate-simple.rb', line 15

def has_next_page?
  current_page < num_of_pages
end

#has_previous_page?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/paginate-simple.rb', line 19

def has_previous_page?
  current_page > first_page
end

#last_pageObject



27
28
29
# File 'lib/paginate-simple.rb', line 27

def last_page
  num_of_pages
end

#next_pageObject



39
40
41
# File 'lib/paginate-simple.rb', line 39

def next_page
  has_next_page? ? current_page + 1 : nil
end

#num_of_pagesObject



11
12
13
# File 'lib/paginate-simple.rb', line 11

def num_of_pages
  (total.to_f / per_page.to_f).ceil 
end

#offsetObject



35
36
37
# File 'lib/paginate-simple.rb', line 35

def offset
  (current_page - 1) * per_page
end

#pagesObject



31
32
33
# File 'lib/paginate-simple.rb', line 31

def pages
  (first_page..last_page).to_a
end

#previous_pageObject



43
44
45
# File 'lib/paginate-simple.rb', line 43

def previous_page
  has_previous_page? ? current_page - 1 : nil
end