Module: Herald::Watcher::Website
- Defined in:
- lib/herald/watchers/website.rb
Instance Attribute Summary collapse
-
#selectors ⇒ Object
Returns the value of attribute selectors.
-
#traverse ⇒ Object
Returns the value of attribute traverse.
-
#uris ⇒ Object
Returns the value of attribute uris.
Class Method Summary collapse
-
.included(base) ⇒ Object
lazy-load open-uri when this Module is used.
Instance Method Summary collapse
Instance Attribute Details
#selectors ⇒ Object
Returns the value of attribute selectors.
6 7 8 |
# File 'lib/herald/watchers/website.rb', line 6 def selectors @selectors end |
#traverse ⇒ Object
Returns the value of attribute traverse.
6 7 8 |
# File 'lib/herald/watchers/website.rb', line 6 def traverse @traverse end |
#uris ⇒ Object
Returns the value of attribute uris.
6 7 8 |
# File 'lib/herald/watchers/website.rb', line 6 def uris @uris end |
Class Method Details
.included(base) ⇒ Object
lazy-load open-uri when this Module is used
9 10 11 12 13 |
# File 'lib/herald/watchers/website.rb', line 9 def self.included(base) %w(open-uri hpricot crack).each do |lib| Herald.lazy_load(lib) end end |
Instance Method Details
#cleanup ⇒ Object
44 |
# File 'lib/herald/watchers/website.rb', line 44 def cleanup; end |
#parse_options(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/herald/watchers/website.rb', line 15 def () # assign an array of selectors # user can pass in either :only_in_tag[s], or :within_tag[s]. # :only_in_tag will limit hpricot to search for text # in that particular tag only, whereas :within_tag will # include all children of the tag in the search # find the option param that matches "tag" .find do |k, v| if k.to_s.match(/tag/) @selectors = Array(v) # coerce to Array # if the key is :only_tag[s] @traverse = false if k.to_s.match(/only/) end end # default selector if no relevant option passed @selectors ||= ["body"] # if we should traverse, append a * (css for "every child") to all selectors if @traverse @selectors.map!{|s|"#{s} *"} end # parse uri Strings to URI objects @uris = Array(.delete(:from)) if @uris.empty? raise ArgumentError, "Website source not specified in :from Hash" end @uris.map!{ |uri| URI.escape(uri) } end |
#prepare ⇒ Object
43 |
# File 'lib/herald/watchers/website.rb', line 43 def prepare; end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/herald/watchers/website.rb', line 46 def to_s "Herald Website Watcher, URIs: #{@uris}, Elements #{@selectors}, Keywords: '#{@keywords}', Timer: #{@timer}, State: #{@keep_alive ? 'Watching' : 'Stopped'}" end |