Class: WCC::Site
- Inherits:
-
Object
- Object
- WCC::Site
- Defined in:
- lib/wcc/site.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#check_interval ⇒ Object
readonly
Returns the value of attribute check_interval.
-
#cookie ⇒ Object
readonly
Returns the value of attribute cookie.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#notify ⇒ Object
readonly
Returns the value of attribute notify.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #content ⇒ Object
- #content=(content) ⇒ Object
- #fetch ⇒ Object
- #fetch_redirect(new_uri) ⇒ Object
- #hash ⇒ Object
- #hash=(hash) ⇒ Object
-
#initialize(url, strip_html, notify, filters, auth, cookie, check_interval) ⇒ Site
constructor
A new instance of Site.
- #load_content ⇒ Object
- #load_hash ⇒ Object
- #new? ⇒ Boolean
- #strip_html? ⇒ Boolean
Constructor Details
#initialize(url, strip_html, notify, filters, auth, cookie, check_interval) ⇒ Site
Returns a new instance of Site.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/wcc/site.rb', line 6 def initialize(url, strip_html, notify, filters, auth, , check_interval) @uri = URI.parse(url) @strip_html = strip_html @notify = notify.is_a?(Array) ? notify : [notify] @filters = filters.is_a?(Array) ? filters : [filters] @auth = auth @cookie = @check_interval = check_interval @id = Digest::MD5.hexdigest(url.to_s)[0...8] # invalid hashes are "" load_hash end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
4 5 6 |
# File 'lib/wcc/site.rb', line 4 def auth @auth end |
#check_interval ⇒ Object (readonly)
Returns the value of attribute check_interval.
4 5 6 |
# File 'lib/wcc/site.rb', line 4 def check_interval @check_interval end |
#cookie ⇒ Object (readonly)
Returns the value of attribute cookie.
4 5 6 |
# File 'lib/wcc/site.rb', line 4 def @cookie end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
4 5 6 |
# File 'lib/wcc/site.rb', line 4 def filters @filters end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/wcc/site.rb', line 4 def id @id end |
#notify ⇒ Object (readonly)
Returns the value of attribute notify.
4 5 6 |
# File 'lib/wcc/site.rb', line 4 def notify @notify end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
4 5 6 |
# File 'lib/wcc/site.rb', line 4 def uri @uri end |
Instance Method Details
#content ⇒ Object
50 |
# File 'lib/wcc/site.rb', line 50 def content; load_content if @content.nil?; @content end |
#content=(content) ⇒ Object
52 53 54 55 |
# File 'lib/wcc/site.rb', line 52 def content=(content) @content = content File.open(Conf.file(@id + '.site'), 'w') { |f| f.write(@content) } unless Conf.simulate? end |
#fetch ⇒ Object
57 58 59 |
# File 'lib/wcc/site.rb', line 57 def fetch retrieve(@uri) end |
#fetch_redirect(new_uri) ⇒ Object
61 62 63 |
# File 'lib/wcc/site.rb', line 61 def fetch_redirect(new_uri) retrieve(new_uri) end |
#hash ⇒ Object
43 |
# File 'lib/wcc/site.rb', line 43 def hash; @hash end |
#hash=(hash) ⇒ Object
45 46 47 48 |
# File 'lib/wcc/site.rb', line 45 def hash=(hash) @hash = hash File.open(Conf.file(@id + '.md5'), 'w') { |f| f.write(@hash) } unless Conf.simulate? end |
#load_content ⇒ Object
36 37 38 39 40 41 |
# File 'lib/wcc/site.rb', line 36 def load_content file = Conf.file(@id + '.site') if File.exists?(file) File.open(file, 'r') { |f| @content = f.read } end end |
#load_hash ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wcc/site.rb', line 25 def load_hash file = Conf.file(@id + '.md5') if File.exists?(file) WCC.logger.debug "Load hash from file '#{file}'" File.open(file, 'r') { |f| @hash = f.gets; break } else WCC.logger.info "Site #{uri.host} was never checked before." @hash = "" end end |
#new? ⇒ Boolean
21 22 23 |
# File 'lib/wcc/site.rb', line 21 def new? hash.empty? end |
#strip_html? ⇒ Boolean
19 |
# File 'lib/wcc/site.rb', line 19 def strip_html?; @strip_html end |