Class: Crawler::Observer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#logObject

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