Class: GearedPagination::Recordset
- Inherits:
-
Object
- Object
- GearedPagination::Recordset
- Defined in:
- lib/geared_pagination/recordset.rb
Instance Attribute Summary collapse
-
#ratios ⇒ Object
readonly
Returns the value of attribute ratios.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
-
#initialize(records, per_page: nil) ⇒ Recordset
constructor
A new instance of Recordset.
- #page(number) ⇒ Object
- #page_count ⇒ Object
- #records_count ⇒ Object
Constructor Details
#initialize(records, per_page: nil) ⇒ Recordset
Returns a new instance of Recordset.
8 9 10 11 |
# File 'lib/geared_pagination/recordset.rb', line 8 def initialize(records, per_page: nil) @records = records @ratios = GearedPagination::Ratios.new(per_page) end |
Instance Attribute Details
#ratios ⇒ Object (readonly)
Returns the value of attribute ratios.
6 7 8 |
# File 'lib/geared_pagination/recordset.rb', line 6 def ratios @ratios end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
6 7 8 |
# File 'lib/geared_pagination/recordset.rb', line 6 def records @records end |
Instance Method Details
#page(number) ⇒ Object
13 14 15 |
# File 'lib/geared_pagination/recordset.rb', line 13 def page(number) GearedPagination::Page.new(number, from: self) end |
#page_count ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/geared_pagination/recordset.rb', line 17 def page_count @page_count ||= begin count = 0 residual = records_count while residual > 0 count += 1 residual = residual - ratios[count] end count end end |
#records_count ⇒ Object
31 32 33 |
# File 'lib/geared_pagination/recordset.rb', line 31 def records_count @records_count ||= records.unscope(:limit).unscope(:offset).count end |