class Spiderman::Runner

Attributes

handlers[R]

Allow access for dup

headers[R]
urls[R]

Public Class Methods

new() click to toggle source
# File lib/spiderman/runner.rb, line 6
def initialize
  @urls = []
  @handlers = {}
  @headers = {}
end

Public Instance Methods

dup() click to toggle source
# File lib/spiderman/runner.rb, line 34
def dup
  self.class.new.tap do |obj|
    obj.urls.replace(urls)
    obj.handlers.update(handlers)
    obj.headers.update(headers)
    obj.logger = logger
  end
end
handler_for(name) click to toggle source
# File lib/spiderman/runner.rb, line 20
def handler_for(name)
  @handlers[name]
end
http() click to toggle source
# File lib/spiderman/runner.rb, line 24
def http
  HTTP.use(logging: {logger: logger}).headers(headers).follow
end
register(name, &handler) click to toggle source
# File lib/spiderman/runner.rb, line 16
def register(name, &handler)
  @handlers[name] = handler
end
request(url) click to toggle source
# File lib/spiderman/runner.rb, line 28
def request(url)
  http.get(url).tap do |response|
    response.extend HTTP::ActAsNokogiriDocument
  end
end
start_at(*urls) click to toggle source
# File lib/spiderman/runner.rb, line 12
def start_at(*urls)
  @urls.append(*urls)
end