Class: OpenLogCleaner::RpolDocument
- Inherits:
-
Document
- Object
- Document
- OpenLogCleaner::RpolDocument
show all
- Defined in:
- lib/openlogcleaner/rpol_document.rb
Instance Attribute Summary
Attributes inherited from Document
#files, #messages, #title
Instance Method Summary
collapse
Methods inherited from Document
#initialize
Instance Method Details
#add_io(io) ⇒ Object
/(?:Re:s*)?(w+ #1) by (.+)$/
10
11
12
13
14
15
16
|
# File 'lib/openlogcleaner/rpol_document.rb', line 10
def add_io(io)
contents = io.read.split(/={10,}/)
contents.pop
contents.shift
add_messages(contents)
end
|
#add_messages(contents) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/openlogcleaner/rpol_document.rb', line 18
def add_messages(contents)
contents.each do |message|
title, body = message.split(/-{10,}/, 2)
nick = extract_nick_and_set_title(title)
messages << Say.new(nick, fix_body(body))
end
end
|
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/openlogcleaner/rpol_document.rb', line 61
def
<<-CSS
.red {
color : #ff0000;
}
.orange {
color : #ff6600;
}
.aqua {
color : #339999;
}
.blue {
color : #0000ff;
}
.darkblue {
color : #000099;
}
.green {
color : #009900;
}
.darkgreen {
color : #006600;
}
.brown {
color : #663300;
}
.purple {
color : #990099;
}
.yellow {
color : #cc9933;
}
.pink {
color : #cc66cc;
}
.invis {
color: #000000;
}
CSS
end
|
#extract_nick_and_set_title(title) ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/openlogcleaner/rpol_document.rb', line 26
def extract_nick_and_set_title(title)
title.gsub!('<br />','')
title.strip!
if title =~ /(?:Re:\s*)?(\w+ #1) by (.+)$/
self.title = $1
$2 else
raise ArgumentError, "Not a valid title string"
end
end
|
#fix_body(body) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/openlogcleaner/rpol_document.rb', line 37
def fix_body(body)
body.gsub!(' ',' ')
body.gsub!(/-{6,}/,'<hr />')
doc = Nokogiri::HTML.parse(body)
doc.css('p.messsage_information').remove
doc.at('body').children.at('br').remove
doc.search('font').each do |font|
font.name = 'span'
end
text = doc.at('body').children.to_xhtml
text.gsub!(/(\s*<br \/>)+\z/m, '')
text
end
|