Class: Que::Web::Pager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_no, page_size, total) ⇒ Pager

Returns a new instance of Pager.



4
5
6
7
8
9
10
# File 'lib/que/web/pager.rb', line 4

def initialize(page_no, page_size, total)
  @current_page = page_no > 1 ? page_no : 1
  @page_size = page_size
  @total = total

  @page_count = total > 0 ? (total / page_size.to_f).ceil : 1
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



2
3
4
# File 'lib/que/web/pager.rb', line 2

def current_page
  @current_page
end

#page_countObject (readonly)

Returns the value of attribute page_count.



2
3
4
# File 'lib/que/web/pager.rb', line 2

def page_count
  @page_count
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



2
3
4
# File 'lib/que/web/pager.rb', line 2

def page_size
  @page_size
end

#totalObject (readonly)

Returns the value of attribute total.



2
3
4
# File 'lib/que/web/pager.rb', line 2

def total
  @total
end

Instance Method Details

#next_pageObject



12
13
14
# File 'lib/que/web/pager.rb', line 12

def next_page
  @current_page < @page_count ? (@current_page + 1) : nil
end

#offsetObject



20
21
22
# File 'lib/que/web/pager.rb', line 20

def offset
  (@current_page - 1) * @page_size
end

#prev_pageObject



16
17
18
# File 'lib/que/web/pager.rb', line 16

def prev_page
  @current_page > 1 ? (@current_page - 1) : nil
end