Class: ParamsReady::Pagination::AfterKeysets
- Inherits:
-
AbstractKeysets
- Object
- AbstractKeysets
- ParamsReady::Pagination::AfterKeysets
- Defined in:
- lib/params_ready/pagination/keysets.rb
Instance Attribute Summary collapse
-
#last ⇒ Object
readonly
Returns the value of attribute last.
Attributes inherited from AbstractKeysets
Instance Method Summary collapse
-
#initialize(last, keysets, &block) ⇒ AfterKeysets
constructor
A new instance of AfterKeysets.
- #page(delta, limit) ⇒ Object
Methods inherited from AbstractKeysets
Constructor Details
#initialize(last, keysets, &block) ⇒ AfterKeysets
Returns a new instance of AfterKeysets.
45 46 47 48 |
# File 'lib/params_ready/pagination/keysets.rb', line 45 def initialize(last, keysets, &block) @last = last super keysets, &block end |
Instance Attribute Details
#last ⇒ Object (readonly)
Returns the value of attribute last.
43 44 45 |
# File 'lib/params_ready/pagination/keysets.rb', line 43 def last @last end |
Instance Method Details
#page(delta, limit) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/params_ready/pagination/keysets.rb', line 50 def page(delta, limit) raise "Expected positive integer for limit, got: #{limit}" if limit < 1 raise "Expected positive integer for delta, got: #{delta}" if delta < 1 return if @keysets.length.zero? shift = (delta - 1) * limit if shift == 0 @last else diff = @keysets.length - shift if diff < 1 nil else transform(@keysets[shift - 1]) end end end |