module Harvesting::Enumerable

Public Instance Methods

each(start = 0) { |element| ... } click to toggle source

@return [Enumerator]

# File lib/harvesting/enumerable.rb, line 10
def each(start = 0, &block)
  @cursor = start
  return to_enum(:each, start) unless block_given?
  Array(@entries[start..-1]).each_with_index do |element, index|
    @cursor = index
    yield(element)
  end

  unless last?
    start = [@entries.size, start].max
    fetch_next_page
    each(start, &block)
  end
  self
end

Private Instance Methods

last?() click to toggle source

@return [Boolean]

# File lib/harvesting/enumerable.rb, line 29
def last?
  (((page - 1) * per_page) + @cursor) >= (total_entries - 1)
end