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.



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

#errorObject (readonly)

Returns the value of attribute error.



6
7
8
# File 'lib/crawl/page.rb', line 6

def error
  @error
end

#registerObject (readonly)

Returns the value of attribute register.



6
7
8
# File 'lib/crawl/page.rb', line 6

def register
  @register
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/crawl/page.rb', line 6

def source
  @source
end

#urlObject (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

Returns:

  • (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

#hashObject



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_urlObject



18
19
20
# File 'lib/crawl/page.rb', line 18

def relative_url
  @relative_url ||= URI.join('http://example.com', source, url).path
end

#successObject



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

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

#to_sObject



56
57
58
# File 'lib/crawl/page.rb', line 56

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