Module: ToughGuy::Query::PaginationMethods
- Defined in:
- lib/toughguy/query.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
Returns the value of attribute current_page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#total_count ⇒ Object
Returns the value of attribute total_count.
-
#total_pages ⇒ Object
Returns the value of attribute total_pages.
Instance Method Summary collapse
-
#current_page_record_range ⇒ Object
Returns the record range for the current page.
-
#next_page ⇒ Object
Returns the next page number or nil if the current page is the last page.
-
#page_range ⇒ Object
Returns the page range.
-
#prev_page ⇒ Object
Returns the previous page number or nil if the current page is the first.
Instance Attribute Details
#current_page ⇒ Object
Returns the value of attribute current_page.
168 169 170 |
# File 'lib/toughguy/query.rb', line 168 def current_page @current_page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
168 169 170 |
# File 'lib/toughguy/query.rb', line 168 def per_page @per_page end |
#total_count ⇒ Object
Returns the value of attribute total_count.
168 169 170 |
# File 'lib/toughguy/query.rb', line 168 def total_count @total_count end |
#total_pages ⇒ Object
Returns the value of attribute total_pages.
168 169 170 |
# File 'lib/toughguy/query.rb', line 168 def total_pages @total_pages end |
Instance Method Details
#current_page_record_range ⇒ Object
Returns the record range for the current page
186 187 188 189 190 191 192 193 |
# File 'lib/toughguy/query.rb', line 186 def current_page_record_range return (0..0) if @current_page > @total_pages a = 1 + (@current_page - 1) * @per_page b = a + @per_page - 1 b = @total_count if b > @total_count a..b end |
#next_page ⇒ Object
Returns the next page number or nil if the current page is the last page
176 177 178 |
# File 'lib/toughguy/query.rb', line 176 def next_page @current_page < @total_pages ? (@current_page + 1) : nil end |
#page_range ⇒ Object
Returns the page range
181 182 183 |
# File 'lib/toughguy/query.rb', line 181 def page_range 1..@total_pages end |
#prev_page ⇒ Object
Returns the previous page number or nil if the current page is the first
171 172 173 |
# File 'lib/toughguy/query.rb', line 171 def prev_page @current_page > 1 ? (@current_page - 1) : nil end |