Class: DHS::Pagination::NextOffset

Inherits:
Base
  • Object
show all
Defined in:
lib/dhs/pagination/next_offset.rb

Constant Summary collapse

DEFAULT_OFFSET =
0

Constants inherited from Base

Base::DEFAULT_LIMIT

Instance Attribute Summary

Attributes inherited from Base

#data

Instance Method Summary collapse

Methods inherited from Base

#current_page, #first_page, #initialize, #last_page, #limit, #limit_value, #next?, #next_offset, #next_page, #offset, page_to_offset, #pages_left, #prev_page, #previous?, #total_pages

Constructor Details

This class inherits a constructor from DHS::Pagination::Base

Instance Method Details

#next(current) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/dhs/pagination/next_offset.rb', line 21

def next(current)
  next_value = current.dig(*_record.pagination_key(:body))
  return if next_value.blank? || next_value.zero?
  {
    _record.pagination_key(:parameter) => current.dig(*_record.pagination_key(:body))
  }
end

#pages_left?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/dhs/pagination/next_offset.rb', line 16

def pages_left?
  next_offset = data._raw.dig(*_record.pagination_key(:body))
  next_offset.present? && !next_offset.zero?
end

#parallel?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/dhs/pagination/next_offset.rb', line 12

def parallel?
  false
end

#totalObject Also known as: count



7
8
9
# File 'lib/dhs/pagination/next_offset.rb', line 7

def total
  data._raw.dig(*_record.items_key).count || 0
end