Class: WCC::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/wcc/site.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, cookie, 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 = cookie
	@check_interval = check_interval
	@id = Digest::MD5.hexdigest(url.to_s)[0...8]
	# invalid hashes are ""
	load_hash
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



4
5
6
# File 'lib/wcc/site.rb', line 4

def auth
  @auth
end

#check_intervalObject (readonly)

Returns the value of attribute check_interval.



4
5
6
# File 'lib/wcc/site.rb', line 4

def check_interval
  @check_interval
end

Returns the value of attribute cookie.



4
5
6
# File 'lib/wcc/site.rb', line 4

def cookie
  @cookie
end

#filtersObject (readonly)

Returns the value of attribute filters.



4
5
6
# File 'lib/wcc/site.rb', line 4

def filters
  @filters
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/wcc/site.rb', line 4

def id
  @id
end

#notifyObject (readonly)

Returns the value of attribute notify.



4
5
6
# File 'lib/wcc/site.rb', line 4

def notify
  @notify
end

#uriObject (readonly)

Returns the value of attribute uri.



4
5
6
# File 'lib/wcc/site.rb', line 4

def uri
  @uri
end

Instance Method Details

#contentObject



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

#fetchObject



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

#hashObject



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_contentObject



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_hashObject



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

Returns:

  • (Boolean)


21
22
23
# File 'lib/wcc/site.rb', line 21

def new?
	hash.empty?
end

#strip_html?Boolean

Returns:

  • (Boolean)


19
# File 'lib/wcc/site.rb', line 19

def strip_html?; @strip_html end