Class: Relevance::Tarantula::Link
Constant Summary
collapse
- METHOD_REGEXPS =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#log, #rails_root, #tarantula_home, #verbose
Constructor Details
#initialize(link, crawler, referrer) ⇒ Link
Returns a new instance of Link.
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/relevance/tarantula/link.rb', line 23
def initialize(link, crawler, referrer)
@crawler, @referrer = crawler, referrer
if String === link || link.nil?
@href = transform_url(link)
@method = :get
else @href = link['href'] ? transform_url(link['href'].downcase) : nil
@tag = link
end
end
|
Instance Attribute Details
Returns the value of attribute crawler.
21
22
23
|
# File 'lib/relevance/tarantula/link.rb', line 21
def crawler
@crawler
end
|
Returns the value of attribute href.
21
22
23
|
# File 'lib/relevance/tarantula/link.rb', line 21
def href
@href
end
|
Returns the value of attribute referrer.
21
22
23
|
# File 'lib/relevance/tarantula/link.rb', line 21
def referrer
@referrer
end
|
Class Method Details
.protect_against_forgery? ⇒ Boolean
method_javascript_function needs this method
7
8
9
|
# File 'lib/relevance/tarantula/link.rb', line 7
def protect_against_forgery?
false
end
|
Instance Method Details
#==(obj) ⇒ Object
Also known as:
eql?
62
63
64
65
|
# File 'lib/relevance/tarantula/link.rb', line 62
def ==(obj)
obj.respond_to?(:href) && obj.respond_to?(:method) &&
self.href.to_s == obj.href.to_s && self.method.to_s == obj.method.to_s
end
|
35
36
37
38
39
|
# File 'lib/relevance/tarantula/link.rb', line 35
def crawl
response = crawler.follow(method, href)
log "Response #{response.code} for #{self}"
crawler.handle_link_results(self, make_result(response))
end
|
68
69
70
|
# File 'lib/relevance/tarantula/link.rb', line 68
def hash
to_s.hash
end
|
#make_result(response) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/relevance/tarantula/link.rb', line 41
def make_result(response)
crawler.make_result(:method => method,
:url => href,
:response => response,
:referrer => referrer)
end
|
48
49
50
51
52
53
54
55
56
|
# File 'lib/relevance/tarantula/link.rb', line 48
def method
@method ||= begin
(@tag &&
[:put, :delete, :post].detect do |m| @tag['onclick'] =~ METHOD_REGEXPS[m]
end) ||
:get
end
end
|
72
73
74
|
# File 'lib/relevance/tarantula/link.rb', line 72
def to_s
"<Relevance::Tarantula::Link href=#{href}, method=#{method}>"
end
|
58
59
60
|
# File 'lib/relevance/tarantula/link.rb', line 58
def transform_url(link)
crawler.transform_url(link)
end
|