Class: Magellan::ExpectedLinksTracker
- Inherits:
-
Object
- Object
- Magellan::ExpectedLinksTracker
- Includes:
- Observable
- Defined in:
- lib/magellan/expected_links_tracker.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #failed? ⇒ Boolean
- #failure_message ⇒ Object
- #has_errors? ⇒ Boolean
-
#initialize(expected_patterns) ⇒ ExpectedLinksTracker
constructor
A new instance of ExpectedLinksTracker.
- #patterns_that_apply(result) ⇒ Object
- #unmet_expecations ⇒ Object
- #unmet_expecations? ⇒ Boolean
- #unmet_expecations_messages ⇒ Object
- #update(time, result) ⇒ Object
Constructor Details
#initialize(expected_patterns) ⇒ ExpectedLinksTracker
Returns a new instance of ExpectedLinksTracker.
6 7 8 9 10 |
# File 'lib/magellan/expected_links_tracker.rb', line 6 def initialize(expected_patterns) @errors = [] @expected_patterns = expected_patterns @evaluated_expectations = {} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/magellan/expected_links_tracker.rb', line 4 def errors @errors end |
Instance Method Details
#failed? ⇒ Boolean
38 39 40 |
# File 'lib/magellan/expected_links_tracker.rb', line 38 def failed? unmet_expecations? || has_errors? end |
#failure_message ⇒ Object
42 43 44 |
# File 'lib/magellan/expected_links_tracker.rb', line 42 def << errors.join("\n") end |
#has_errors? ⇒ Boolean
30 31 32 |
# File 'lib/magellan/expected_links_tracker.rb', line 30 def has_errors? !@errors.empty? end |
#patterns_that_apply(result) ⇒ Object
24 25 26 27 28 |
# File 'lib/magellan/expected_links_tracker.rb', line 24 def patterns_that_apply(result) res = @expected_patterns.select{|pattern,expecation| result.url =~ pattern || result.destination_url =~ pattern} res.each { |expected_pattern| @evaluated_expectations[expected_pattern] = nil } res end |
#unmet_expecations ⇒ Object
52 53 54 |
# File 'lib/magellan/expected_links_tracker.rb', line 52 def unmet_expecations @expected_patterns - @evaluated_expectations.keys end |
#unmet_expecations? ⇒ Boolean
34 35 36 |
# File 'lib/magellan/expected_links_tracker.rb', line 34 def unmet_expecations? !unmet_expecations.empty? end |
#unmet_expecations_messages ⇒ Object
46 47 48 49 50 |
# File 'lib/magellan/expected_links_tracker.rb', line 46 def = "" unmet_expecations.each {|pattern,unmet_expecation| << "#{pattern} was never evaluted during the crawl\n"} end |
#update(time, result) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/magellan/expected_links_tracker.rb', line 12 def update(time,result) if result.html_content? patterns_that_apply(result).each do |pattern,expectation| passed = result.linked_resources.include?(expectation) changed = "#{result.url} did not contain a link to #{expectation}" notify_observers(Time.now, passed, ) @errors << unless passed end end end |