Class: ParamsReady::Pagination::BeforeKeysets

Inherits:
AbstractKeysets show all
Defined in:
lib/params_ready/pagination/keysets.rb

Instance Attribute Summary

Attributes inherited from AbstractKeysets

#keysets

Instance Method Summary collapse

Methods inherited from AbstractKeysets

#initialize, #length, #transform

Constructor Details

This class inherits a constructor from ParamsReady::Pagination::AbstractKeysets

Instance Method Details

#page(delta, limit) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/params_ready/pagination/keysets.rb', line 22

def page(delta, limit)
  raise "Expected positive integer for limit, got: #{limit}" if limit < 1
  raise "Expected non-negative integer for delta, got: #{delta}" if delta < 0

  if delta == 0
    transform(@keysets.first)
  else
    shift = delta * limit
    diff = @keysets.length - shift
    if diff > 0
      transform(@keysets[shift])
    elsif diff.abs < limit
      {}
    else
      nil
    end
  end
end