Class: Spiderman::Runner
- Inherits:
-
Object
- Object
- Spiderman::Runner
- Defined in:
- lib/spiderman/runner.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#urls ⇒ Object
readonly
Returns the value of attribute urls.
Instance Method Summary collapse
- #dup ⇒ Object
- #handler_for(name) ⇒ Object
- #http ⇒ Object
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #register(name, &handler) ⇒ Object
- #request(url) ⇒ Object
- #start_at(*urls) ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
6 7 8 9 10 |
# File 'lib/spiderman/runner.rb', line 6 def initialize @urls = [] @handlers = {} @headers = {} end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
4 5 6 |
# File 'lib/spiderman/runner.rb', line 4 def headers @headers end |
#urls ⇒ Object (readonly)
Returns the value of attribute urls.
4 5 6 |
# File 'lib/spiderman/runner.rb', line 4 def urls @urls end |
Instance Method Details
#dup ⇒ Object
34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
20 21 22 |
# File 'lib/spiderman/runner.rb', line 20 def handler_for(name) @handlers[name] end |
#http ⇒ Object
24 25 26 |
# File 'lib/spiderman/runner.rb', line 24 def http HTTP.use(logging: {logger: logger}).headers(headers).follow end |
#register(name, &handler) ⇒ Object
16 17 18 |
# File 'lib/spiderman/runner.rb', line 16 def register(name, &handler) @handlers[name] = handler end |
#request(url) ⇒ Object
28 29 30 31 32 |
# 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) ⇒ Object
12 13 14 |
# File 'lib/spiderman/runner.rb', line 12 def start_at(*urls) @urls.append(*urls) end |