Class: TinyPaginate::Page
- Inherits:
-
Object
- Object
- TinyPaginate::Page
- Defined in:
- lib/tiny_paginate/page.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#page_number ⇒ Object
Returns the value of attribute page_number.
Instance Method Summary collapse
- #first_page? ⇒ Boolean
-
#initialize(page_number:, collection:) ⇒ Page
constructor
A new instance of Page.
- #last_page? ⇒ Boolean
- #next_page ⇒ Object
- #previous_page ⇒ Object
- #records ⇒ Object
Constructor Details
#initialize(page_number:, collection:) ⇒ Page
Returns a new instance of Page.
5 6 7 8 |
# File 'lib/tiny_paginate/page.rb', line 5 def initialize(page_number:, collection:) @page_number = page_number @collection = collection end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
3 4 5 |
# File 'lib/tiny_paginate/page.rb', line 3 def collection @collection end |
#page_number ⇒ Object
Returns the value of attribute page_number.
3 4 5 |
# File 'lib/tiny_paginate/page.rb', line 3 def page_number @page_number end |
Instance Method Details
#first_page? ⇒ Boolean
22 23 24 |
# File 'lib/tiny_paginate/page.rb', line 22 def first_page? page_number == 1 end |
#last_page? ⇒ Boolean
26 27 28 |
# File 'lib/tiny_paginate/page.rb', line 26 def last_page? page_number >= (collection.length.to_f / TinyPaginate.max_records_per_page).ceil end |
#next_page ⇒ Object
14 15 16 |
# File 'lib/tiny_paginate/page.rb', line 14 def next_page page_number + 1 end |
#previous_page ⇒ Object
18 19 20 |
# File 'lib/tiny_paginate/page.rb', line 18 def previous_page page_number - 1 end |
#records ⇒ Object
10 11 12 |
# File 'lib/tiny_paginate/page.rb', line 10 def records collection.offset(offset).limit(TinyPaginate.max_records_per_page) end |