Sha256: ab0088590b219b0e0a3fd5d621a74bf732621301eb71bbf11d44860b96fd4809

Contents?: true

Size: 681 Bytes

Versions: 3

Compression:

Stored size: 681 Bytes

Contents

require 'anemone/http'

module Anemone
  class Tentacle
    
    #
    # Create a new Tentacle
    #
    def initialize(link_queue, page_queue, opts = {})
      @link_queue = link_queue
      @page_queue = page_queue
      @http = Anemone::HTTP.new(opts)
      @opts = opts
    end
    
    #
    # Gets links from @link_queue, and returns the fetched
    # Page objects into @page_queue
    #
    def run
      loop do
        link, from_page = @link_queue.deq
        
        break if link == :END

        @page_queue << @http.fetch_page(link, from_page)

        delay
      end
    end

    private

    def delay
      sleep @opts[:delay] if @opts[:delay]
    end

  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
spk-anemone-0.2.4 lib/anemone/tentacle.rb
shingara-anemone-0.2.4 lib/anemone/tentacle.rb
anemone-0.2.3 lib/anemone/tentacle.rb