Sha256: 171b4e3533460ac2eb23d91aea93e07170fa4440c05493e6d70545584e1859a2

Contents?: true

Size: 711 Bytes

Versions: 3

Compression:

Stored size: 711 Bytes

Contents

# @see https://github.com/sferik/twitter/blob/aa909b3b7733ca619d80f1c8cba961033d1fc7e6/lib/twitter/enumerable.rb
module Harvesting
  module Enumerable
    include ::Enumerable

    # @return [Enumerator]
    def each(start = 0)
      @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, &Proc.new)
      end
      self
    end

  private

    # @return [Boolean]
    def last?
      (((page - 1) * per_page) + @cursor) >= (total_entries - 1)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
harvesting-0.3.0 lib/harvesting/enumerable.rb
harvesting-0.2.0 lib/harvesting/enumerable.rb
harvesting-0.1.0 lib/harvesting/enumerable.rb