Class: GearedPagination::Page
- Inherits:
-
Object
- Object
- GearedPagination::Page
- Defined in:
- lib/geared_pagination/page.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #first? ⇒ Boolean
-
#initialize(number, from:) ⇒ Page
constructor
A new instance of Page.
- #last? ⇒ Boolean
- #next_number ⇒ Object
- #only? ⇒ Boolean
- #records ⇒ Object
- #used? ⇒ Boolean
Constructor Details
#initialize(number, from:) ⇒ Page
Returns a new instance of Page.
7 8 9 10 |
# File 'lib/geared_pagination/page.rb', line 7 def initialize(number, from:) @number, @collection = number, from @portion = GearedPagination::Portion.new(page_number: number, per_page: from.ratios) end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
5 6 7 |
# File 'lib/geared_pagination/page.rb', line 5 def collection @collection end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
5 6 7 |
# File 'lib/geared_pagination/page.rb', line 5 def number @number end |
Instance Method Details
#empty? ⇒ Boolean
21 22 23 |
# File 'lib/geared_pagination/page.rb', line 21 def empty? records.load.none? end |
#first? ⇒ Boolean
26 27 28 |
# File 'lib/geared_pagination/page.rb', line 26 def first? number == 1 end |
#last? ⇒ Boolean
34 35 36 |
# File 'lib/geared_pagination/page.rb', line 34 def last? number == collection.page_count end |
#next_number ⇒ Object
39 40 41 |
# File 'lib/geared_pagination/page.rb', line 39 def next_number number + 1 end |
#only? ⇒ Boolean
30 31 32 |
# File 'lib/geared_pagination/page.rb', line 30 def only? collection.page_count == 1 end |
#records ⇒ Object
12 13 14 |
# File 'lib/geared_pagination/page.rb', line 12 def records @records ||= @portion.from(collection.records) end |
#used? ⇒ Boolean
17 18 19 |
# File 'lib/geared_pagination/page.rb', line 17 def used? records.load.any? end |