Class: Magellan::ExpectedLinksTracker
- Inherits:
-
Object
- Object
- Magellan::ExpectedLinksTracker
- Includes:
- Observable
- Defined in:
- lib/magellan/expected_links_tracker.rb
Overview
The observer that will listen to all results and compare them to a list of rules about expected urls.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
An array of failed expecations.
Instance Method Summary collapse
-
#failed? ⇒ Boolean
Are there expected urls that have not been found yet, or pages that have been found with missing links?.
-
#failure_message ⇒ Object
A string summary of all failure messages.
-
#has_errors? ⇒ Boolean
:nodoc:.
-
#initialize(expected_patterns) ⇒ ExpectedLinksTracker
constructor
Create a new expected links tracker.
-
#patterns_that_apply(result) ⇒ Object
:nodoc:.
-
#unmet_expecations ⇒ Object
Expecations that have never been evaluated.
-
#unmet_expecations? ⇒ Boolean
:nodoc:.
-
#unmet_expecations_messages ⇒ Object
:nodoc:.
-
#update(time, result) ⇒ Object
The updates that come in via a observable subject, the time the result came at and the Magellan::Result itself.
Constructor Details
#initialize(expected_patterns) ⇒ ExpectedLinksTracker
Create a new expected links tracker. An array of tuples of the url pattern and expected link is a required argument. Example: Magellan::ExpectedLinksTracker.new([])
12 13 14 15 16 |
# File 'lib/magellan/expected_links_tracker.rb', line 12 def initialize(expected_patterns) @errors = [] @expected_patterns = expected_patterns @evaluated_expectations = {} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
An array of failed expecations
6 7 8 |
# File 'lib/magellan/expected_links_tracker.rb', line 6 def errors @errors end |
Instance Method Details
#failed? ⇒ Boolean
Are there expected urls that have not been found yet, or pages that have been found with missing links?
46 47 48 |
# File 'lib/magellan/expected_links_tracker.rb', line 46 def failed? unmet_expecations? || has_errors? end |
#failure_message ⇒ Object
A string summary of all failure messages
51 52 53 |
# File 'lib/magellan/expected_links_tracker.rb', line 51 def << errors.join("\n") end |
#has_errors? ⇒ Boolean
:nodoc:
37 38 39 |
# File 'lib/magellan/expected_links_tracker.rb', line 37 def has_errors? # :nodoc: !@errors.empty? end |
#patterns_that_apply(result) ⇒ Object
:nodoc:
31 32 33 34 35 |
# File 'lib/magellan/expected_links_tracker.rb', line 31 def patterns_that_apply(result) # :nodoc: 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
Expecations that have never been evaluated
62 63 64 |
# File 'lib/magellan/expected_links_tracker.rb', line 62 def unmet_expecations @expected_patterns - @evaluated_expectations.keys end |
#unmet_expecations? ⇒ Boolean
:nodoc:
41 42 43 |
# File 'lib/magellan/expected_links_tracker.rb', line 41 def unmet_expecations? # :nodoc: !unmet_expecations.empty? end |
#unmet_expecations_messages ⇒ Object
:nodoc:
55 56 57 58 59 |
# File 'lib/magellan/expected_links_tracker.rb', line 55 def # :nodoc: = "" unmet_expecations.each {|pattern,unmet_expecation| << "#{pattern} was never evaluted during the crawl\n"} end |
#update(time, result) ⇒ Object
The updates that come in via a observable subject, the time the result came at and the Magellan::Result itself.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/magellan/expected_links_tracker.rb', line 19 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 |