Class: Page

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/crawl/page.rb

Constant Summary collapse

ATTEMPTS =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(register, url, source) ⇒ Page

Returns a new instance of Page.



8
9
10
11
12
13
14
# File 'lib/crawl/page.rb', line 8

def initialize(register, url, source)
  @register = register
  @url = url
  @source = source
  @attempts = 0
  @errors = nil
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



4
5
6
# File 'lib/crawl/page.rb', line 4

def error
  @error
end

#registerObject (readonly)

Returns the value of attribute register.



4
5
6
# File 'lib/crawl/page.rb', line 4

def register
  @register
end

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/crawl/page.rb', line 4

def source
  @source
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/crawl/page.rb', line 4

def url
  @url
end

Instance Method Details

#<=>(other) ⇒ Object



16
17
18
# File 'lib/crawl/page.rb', line 16

def <=>(other)
  url <=> other.url
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/crawl/page.rb', line 20

def eql?(other)
  url.eql?(other.url)
end

#fatal(error) ⇒ Object



33
34
35
36
37
# File 'lib/crawl/page.rb', line 33

def fatal(error)
  puts "  Fatal - #{error}" if $VERBOSE
  @error = error
  @register.completed(self)
end

#hashObject



24
25
26
# File 'lib/crawl/page.rb', line 24

def hash
  url.hash
end

#intermittent(error) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/crawl/page.rb', line 39

def intermittent(error)
  puts "  Intermittent - #{error}" if $VERBOSE
  if @attempts >= ATTEMPTS
    @error = error
    @register.completed(self)
  else
    @attempts += 1
    @register.retry(self)
  end
end

#successObject



28
29
30
31
# File 'lib/crawl/page.rb', line 28

def success
  @error = nil
  @register.completed(self)
end

#to_sObject



50
51
52
# File 'lib/crawl/page.rb', line 50

def to_s
  "#{url} found on #{source} - #{error || 'OK'}"
end