Module: Flex::Struct::Paginable
- Defined in:
- lib/flex/struct/paginable.rb
Instance Attribute Summary collapse
-
#total_entries ⇒ Object
(also: #total_count)
Returns the value of attribute total_entries.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
- #current_page ⇒ Object
- #first_page? ⇒ Boolean
- #last_page? ⇒ Boolean
- #next_page ⇒ Object
- #offset ⇒ Object (also: #offset_value)
- #out_of_bounds? ⇒ Boolean
- #per_page ⇒ Object (also: #limit_value)
- #previous_page ⇒ Object
- #setup(total_entries, variables) ⇒ Object
- #total_pages ⇒ Object (also: #num_pages)
Instance Attribute Details
#total_entries ⇒ Object Also known as: total_count
Returns the value of attribute total_entries.
5 6 7 |
# File 'lib/flex/struct/paginable.rb', line 5 def total_entries @total_entries end |
#variables ⇒ Object
Returns the value of attribute variables.
5 6 7 |
# File 'lib/flex/struct/paginable.rb', line 5 def variables @variables end |
Instance Method Details
#current_page ⇒ Object
22 23 24 |
# File 'lib/flex/struct/paginable.rb', line 22 def current_page (@variables[:page] || @variables[:current_page] || 1).to_i end |
#first_page? ⇒ Boolean
38 39 40 |
# File 'lib/flex/struct/paginable.rb', line 38 def first_page? current_page == 1 end |
#last_page? ⇒ Boolean
34 35 36 |
# File 'lib/flex/struct/paginable.rb', line 34 def last_page? total_pages == current_page end |
#next_page ⇒ Object
30 31 32 |
# File 'lib/flex/struct/paginable.rb', line 30 def next_page current_page < total_pages ? (current_page + 1) : nil end |
#offset ⇒ Object Also known as: offset_value
42 43 44 |
# File 'lib/flex/struct/paginable.rb', line 42 def offset per_page * (current_page - 1) end |
#out_of_bounds? ⇒ Boolean
46 47 48 |
# File 'lib/flex/struct/paginable.rb', line 46 def out_of_bounds? current_page > total_pages end |
#per_page ⇒ Object Also known as: limit_value
13 14 15 16 |
# File 'lib/flex/struct/paginable.rb', line 13 def per_page (@variables[:per_page] || @variables[:limit_value] || @variables[:params] && @variables[:params][:size] || 10).to_i end |
#previous_page ⇒ Object
26 27 28 |
# File 'lib/flex/struct/paginable.rb', line 26 def previous_page current_page > 1 ? (current_page - 1) : nil end |
#setup(total_entries, variables) ⇒ Object
7 8 9 10 11 |
# File 'lib/flex/struct/paginable.rb', line 7 def setup(total_entries, variables) @total_entries = total_entries @variables = variables self end |
#total_pages ⇒ Object Also known as: num_pages
18 19 20 |
# File 'lib/flex/struct/paginable.rb', line 18 def total_pages ( @total_entries.to_f / per_page ).ceil end |