Class: Que::Web::Pager
- Inherits:
-
Object
- Object
- Que::Web::Pager
- Defined in:
- lib/que/web/pager.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#page_count ⇒ Object
readonly
Returns the value of attribute page_count.
-
#page_size ⇒ Object
readonly
Returns the value of attribute page_size.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(page_no, page_size, total) ⇒ Pager
constructor
A new instance of Pager.
- #next_page ⇒ Object
- #offset ⇒ Object
- #prev_page ⇒ Object
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_page ⇒ Object (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_count ⇒ Object (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_size ⇒ Object (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 |
#total ⇒ Object (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_page ⇒ Object
12 13 14 |
# File 'lib/que/web/pager.rb', line 12 def next_page @current_page < @page_count ? (@current_page + 1) : nil end |
#offset ⇒ Object
20 21 22 |
# File 'lib/que/web/pager.rb', line 20 def offset (@current_page - 1) * @page_size end |
#prev_page ⇒ Object
16 17 18 |
# File 'lib/que/web/pager.rb', line 16 def prev_page @current_page > 1 ? (@current_page - 1) : nil end |