Class: Page
Constant Summary collapse
- ATTEMPTS =
3
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#register ⇒ Object
readonly
Returns the value of attribute register.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #fatal(error) ⇒ Object
- #hash ⇒ Object
-
#initialize(register, url, source) ⇒ Page
constructor
A new instance of Page.
- #intermittent(error) ⇒ Object
- #relative_url ⇒ Object
- #success ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(register, url, source) ⇒ Page
Returns a new instance of Page.
10 11 12 13 14 15 16 |
# File 'lib/crawl/page.rb', line 10 def initialize(register, url, source) @register = register @url = url @source = source @attempts = 0 @errors = nil end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/crawl/page.rb', line 6 def error @error end |
#register ⇒ Object (readonly)
Returns the value of attribute register.
6 7 8 |
# File 'lib/crawl/page.rb', line 6 def register @register end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/crawl/page.rb', line 6 def source @source end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/crawl/page.rb', line 6 def url @url end |
Instance Method Details
#<=>(other) ⇒ Object
22 23 24 |
# File 'lib/crawl/page.rb', line 22 def <=>(other) relative_url <=> other.relative_url end |
#eql?(other) ⇒ Boolean
26 27 28 |
# File 'lib/crawl/page.rb', line 26 def eql?(other) relative_url.eql?(other.relative_url) end |
#fatal(error) ⇒ Object
39 40 41 42 43 |
# File 'lib/crawl/page.rb', line 39 def fatal(error) puts " Fatal - #{error}" if $VERBOSE @error = error @register.completed(self) end |
#hash ⇒ Object
30 31 32 |
# File 'lib/crawl/page.rb', line 30 def hash relative_url.hash end |
#intermittent(error) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/crawl/page.rb', line 45 def intermittent(error) puts " Intermittent - #{error}" if $VERBOSE if @attempts >= ATTEMPTS @error = error @register.completed(self) else @attempts += 1 @register.retry(self) end end |
#relative_url ⇒ Object
18 19 20 |
# File 'lib/crawl/page.rb', line 18 def relative_url @relative_url ||= URI.join('http://example.com', source, url).path end |
#success ⇒ Object
34 35 36 37 |
# File 'lib/crawl/page.rb', line 34 def success @error = nil @register.completed(self) end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/crawl/page.rb', line 56 def to_s "#{url} found on #{source} - #{error || 'OK'}" end |