Module: Harvesting::Enumerable

Includes:
Enumerable
Included in:
Models::HarvestRecordCollection
Defined in:
lib/harvesting/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#each(start = 0, &block) ⇒ Enumerator

Returns:

  • (Enumerator)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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