Class: DiffNews::Service
- Inherits:
-
Object
show all
- Defined in:
- lib/service.rb
Constant Summary
collapse
- @@services =
[]
- @@store_class =
DefaultHistory
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(url) ⇒ Service
Returns a new instance of Service.
46
47
48
49
50
51
|
# File 'lib/service.rb', line 46
def initialize url
@url = url
@uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url)
@doc = nil
load_history
end
|
Instance Attribute Details
#history ⇒ Object
Returns the value of attribute history.
17
18
19
|
# File 'lib/service.rb', line 17
def history
@history
end
|
Class Method Details
.create(url) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/service.rb', line 57
def self.create url
match = @@services.select { |s| url =~ s.valid_url }
raise UnknownNewspageError if match.none?
match.first.new url
end
|
.register_service ⇒ Object
53
54
55
|
# File 'lib/service.rb', line 53
def self.register_service
@@services << self
end
|
.services ⇒ Object
22
23
24
|
# File 'lib/service.rb', line 22
def self.services
@@services
end
|
.store_class=(store_class) ⇒ Object
42
43
44
|
# File 'lib/service.rb', line 42
def self.store_class= store_class
@@store_class = store_class
end
|
Instance Method Details
#base_url ⇒ Object
30
31
32
|
# File 'lib/service.rb', line 30
def base_url
self.class.base_url
end
|
#current_revision ⇒ Object
38
39
40
|
# File 'lib/service.rb', line 38
def current_revision
return @history.revisions.last
end
|
#encoding ⇒ Object
34
35
36
|
# File 'lib/service.rb', line 34
def encoding
@doc.encoding
end
|
#normalize_text(text) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/service.rb', line 70
def normalize_text text
empty_lines = 0
result = ''
text.each_line do |line|
line = line.strip
line = line.gsub(/\s+/, ' ')
empty_lines = line.length == 0 ? empty_lines + 1 : 0
if empty_lines < 2
result += line.strip + "\n"
end
end
return result
end
|
#provider ⇒ Object
26
27
28
|
# File 'lib/service.rb', line 26
def provider
self.class.provider
end
|
#strip_html(partial) ⇒ Object
64
65
66
67
68
|
# File 'lib/service.rb', line 64
def strip_html partial
partial.css("br").each { |node| node.replace("\n") }
partial.css("p").each { |node| node.replace("#{node.text.strip}\n\n") }
partial.text.strip
end
|