Class: Pinnacle::Internal::OffsetItemIterator

Inherits:
ItemIterator
  • Object
show all
Defined in:
lib/pinnacle/internal/iterators/offset_item_iterator.rb

Instance Method Summary collapse

Methods inherited from ItemIterator

#each, #next?, #next_element

Constructor Details

#initialize(initial_page:, item_field:, has_next_field:, step:) ⇒ Pinnacle::Internal::OffsetItemIterator

Instantiates an OffsetItemIterator, an Enumerable class which wraps calls to an offset-based paginated API and yields the individual items from it.

Parameters:

  • initial_page (Integer)

    The initial page or offset to start from when iterating.

  • item_field (Symbol)

    The name of the field in API responses to extract the items to iterate over.

  • has_next_field (Symbol)

    The name of the field in API responses containing a boolean of whether another page exists.

  • step (Boolean)

    If true, treats the page number as a true offset (i.e. increments the page number by the number of items returned from each call rather than just 1)

  • block (Proc)

    A block which is responsible for receiving a page number to use and returning the given page from the API.



15
16
17
18
19
20
# File 'lib/pinnacle/internal/iterators/offset_item_iterator.rb', line 15

def initialize(initial_page:, item_field:, has_next_field:, step:, &)
  super()
  @item_field = item_field
  @page_iterator = OffsetPageIterator.new(initial_page:, item_field:, has_next_field:, step:, &)
  @page = nil
end

Instance Method Details

#pagesPinnacle::Internal::OffsetPageIterator

Returns the OffsetPageIterator that is mediating access to the underlying API.



25
26
27
# File 'lib/pinnacle/internal/iterators/offset_item_iterator.rb', line 25

def pages
  @page_iterator
end