Class: Crawler::Observer
- Inherits:
-
Object
- Object
- Crawler::Observer
- Defined in:
- lib/crawler/observer.rb
Overview
Observer watches a Webcrawler and outputs messages to a log object. This defaults to STDOUT but may be anything which responds to puts
.
Instance Attribute Summary collapse
-
#log ⇒ Object
Log object.
Instance Method Summary collapse
-
#initialize(log = $stdout) ⇒ Observer
constructor
Creates a new Observer object.
-
#update(response, url) ⇒ Object
Called by the Observable module through Webcrawler.
Constructor Details
#initialize(log = $stdout) ⇒ Observer
Creates a new Observer object
10 11 12 |
# File 'lib/crawler/observer.rb', line 10 def initialize(log=$stdout) @log = log end |
Instance Attribute Details
#log ⇒ Object
Log object. Must respond to puts
.
7 8 9 |
# File 'lib/crawler/observer.rb', line 7 def log @log end |
Instance Method Details
#update(response, url) ⇒ Object
Called by the Observable module through Webcrawler.
15 16 17 18 19 20 |
# File 'lib/crawler/observer.rb', line 15 def update(response, url) @log.puts "Scanning: " + url.to_s if response.kind_of?(Net::HTTPClientError) or response.kind_of?(Net::HTTPServerError) @log.puts "#{response.code} encountered for " + url.to_s end end |