openlogcleaner 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -14,13 +14,23 @@ module OpenLogCleaner
14
14
  end
15
15
 
16
16
  def self.from_html(msg)
17
- nick = msg.at('span').inner_text.sub(/^\(\d+\)\s+/, '')
18
- msg.at('span').inner_html = nick
17
+ nick = parse_nick(msg)
19
18
  color = msg.at('font')[:color]
20
19
  text = msg.at('font font').inner_html
21
20
  new(nick, text, color)
22
21
  end
23
22
 
23
+ def self.parse_nick(msg)
24
+ if (span = msg.at('span'))
25
+ nick = span.inner_text.sub(/^\(\d+\)\s+/, '')
26
+ span.inner_html = nick
27
+ nick
28
+ else
29
+ msg.at('font').children.first.text =~ /\*\* (.*)$/
30
+ $1.strip
31
+ end
32
+ end
33
+
24
34
  def self.from_hash(msg)
25
35
  new(msg[:nick], msg[:text], msg[:color])
26
36
  end
@@ -55,16 +55,32 @@ module OpenLogCleaner
55
55
 
56
56
  def add_list_entry(dt, dd)
57
57
  name = dt.inner_text
58
- if dt[:style] =~ /color: #([a-f0-9]{6});/i
58
+ if dd[:style] =~ /color: (#[a-f0-9]{6});/i
59
59
  color = $1
60
+ else
61
+ raise "No color"
60
62
  end
61
63
  content = dd.inner_html
62
- say = (dt[:class] && dt[:class] =~ /say/) ? true : false
63
- add_message(say ? Say.new(name, content, color) : Emote.new(name, content, color))
64
+ content.strip!
65
+
66
+ case dt[:class]
67
+ when /say/, /ooc/
68
+ add_message Say.new(name, content, color)
69
+ when /emote/
70
+ add_message Emote.new(name, content, color)
71
+ else
72
+ raise "Unknown class #{dt[:class].inspect}"
73
+ end
64
74
  end
65
75
 
66
76
  def add_post(msg)
67
- return if msg.children.size == 1
77
+ if msg.children.size == 1
78
+ first_childs_first_node = msg.children.first.children.first
79
+ if first_childs_first_node.text? and first_childs_first_node.text =~ /\A\*\*/
80
+ add_message(Emote.from_html(msg))
81
+ end
82
+ return
83
+ end
68
84
  return if msg.at('table') # deal with welcome messages
69
85
 
70
86
  # fix the nick
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{openlogcleaner}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jonathan Stott"]
12
- s.date = %q{2011-02-13}
12
+ s.date = %q{2011-02-15}
13
13
  s.default_executable = %q{openlogcleaner}
14
14
  s.description = %q{Cleans OpenRPG Logs
15
15
 
@@ -41,6 +41,10 @@ Logs are presented in an easy to read manner, stripped of the noise of joins and
41
41
  "lib/openlogcleaner/templates/dokuwiki_formatter.mustache",
42
42
  "lib/openlogcleaner/templates/html_formatter.mustache",
43
43
  "openlogcleaner.gemspec",
44
+ "spec/fixtures/manual2_testlog.htm",
45
+ "spec/fixtures/manual_testlog.htm",
46
+ "spec/fixtures/parsed_testlog.htm",
47
+ "spec/openlogcleaner/html_document_spec.rb",
44
48
  "spec/openlogcleaner_spec.rb",
45
49
  "spec/spec_helper.rb"
46
50
  ]
@@ -49,6 +53,7 @@ Logs are presented in an easy to read manner, stripped of the noise of joins and
49
53
  s.rubygems_version = %q{1.5.0}
50
54
  s.summary = %q{Cleans OpenRPG logs}
51
55
  s.test_files = [
56
+ "spec/openlogcleaner/html_document_spec.rb",
52
57
  "spec/openlogcleaner_spec.rb",
53
58
  "spec/spec_helper.rb"
54
59
  ]
@@ -0,0 +1,93 @@
1
+ <html><body bgcolor="#ffffff" text="#000000">
2
+ <font color='#ff0000'><b>Welcome to <a href='http://www.openrpg.com'>OpenRPG</a> version 1.7.7... </b></font>
3
+ <div class='info'><font color='#ff8000'>Locating server at example.com:6774...</font></div>
4
+ <div class='info'><font color='#ff8000'>Game connected!</font></div>
5
+ <div class='info'><font color='#ff8000'>(2836) User (enter): 21:43</font></div>
6
+ <b><i><u>Server Administrator</u>-></i></b> You have connected to an <a href="http://www.openrpg.com">OpenRPG</a> server, version '1.8.0', named 'Example'.<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
7
+ <html>
8
+
9
+ <table cellspacing=3 cellpadding=4 width="100%">
10
+ <tr>
11
+ <td bgcolor="#101010" align="bottom">
12
+ <center></center>
13
+ </td>
14
+ </tr>
15
+ <tr>
16
+ <td bgcolor="#73A183" align="center">
17
+ <table cellpadding="0" cellspacing="0" width="100%">
18
+ <tr>
19
+ <td align="center" width="100%">
20
+ <h3>Welcome to Example!</h3>
21
+ </td>
22
+ </tr>
23
+ <tr>
24
+ <td align="center" width="100%">
25
+ Please stay a while.
26
+ </td>
27
+ </tr>
28
+ </table>
29
+ </td>
30
+ </tr>
31
+ </table><!-- Created: Thursday November 9 23:55:12 PDT 2003 -->
32
+ <div class='post'><b class='name'>(2836) User</b>: <font color='#004000'>say something</font></div>
33
+ <div class='emote'><font color='#008000'>** <span class='name'>(2836) User</span> <font color='#008000'>emote something</font> **</font></div>
34
+ <div class='post'><b class='name'>(2836) User</b>: <font color='#004000'>(( say something ))</font></div>
35
+ <div class='info'><font color='#ff8000'>Moving to room 'test room'..</font></div>
36
+ <div class='info'><font color='#ff8000'>(2836) User (enter): 21:44</font></div>
37
+ <b><i><u>Server Administrator</u>-></i></b> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
38
+ <html>
39
+
40
+ <table cellspacing=3 cellpadding=4 width="100%">
41
+ <tr>
42
+ <td bgcolor="#101010" align="bottom">
43
+ <center></center>
44
+ </td>
45
+ </tr>
46
+ <tr>
47
+ <td bgcolor="#73A183" align="center">
48
+ <table cellpadding="0" cellspacing="0" width="100%">
49
+ <tr>
50
+ <td align="center" width="100%">
51
+ <h3>Welcome to Example!</h3>
52
+ </td>
53
+ </tr>
54
+ <tr>
55
+ <td align="center" width="100%">
56
+ Please stay a while.
57
+ </td>
58
+ </tr>
59
+ </table>
60
+ </td>
61
+ </tr>
62
+ </table><!-- Created: Thursday November 9 23:55:12 PDT 2003 -->
63
+ <div class='info'><font color='#ff8000'>Moving to room 'Lobby'..</font></div>
64
+ <div class='info'><font color='#ff8000'>(2836) User (enter): 21:44</font></div>
65
+ <b><i><u>Server Administrator</u>-></i></b> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
66
+ <html>
67
+
68
+ <table cellspacing=3 cellpadding=4 width="100%">
69
+ <tr>
70
+ <td bgcolor="#101010" align="bottom">
71
+ <center></center>
72
+ </td>
73
+ </tr>
74
+ <tr>
75
+ <td bgcolor="#73A183" align="center">
76
+ <table cellpadding="0" cellspacing="0" width="100%">
77
+ <tr>
78
+ <td align="center" width="100%">
79
+ <h3>Welcome to Example!</h3>
80
+ </td>
81
+ </tr>
82
+ <tr>
83
+ <td align="center" width="100%">
84
+ Please stay a while.
85
+ </td>
86
+ </tr>
87
+ </table>
88
+ </td>
89
+ </tr>
90
+ </table><!-- Created: Thursday November 9 23:55:12 PDT 2003 -->
91
+ <div class='system'><font color='#ff0000'>Disconnecting from server...</font></div>
92
+ <div class='system'><font color='#ff0000'>Game disconnected!</font></div>
93
+ </body></html>
@@ -0,0 +1,83 @@
1
+ <html><body bgcolor="#ffffff" text="#000000">
2
+ <div class="post"><font color="#ff0000"><b>Welcome to <a href="http://www.openrpg.com">OpenRPG</a> version 1.8.0 ... </b></font></div><div class="post"><font color="#ff8000">Locating server at example.com:6774...</font></div><div class="post"><font color="#ff8000">Game connected!</font></div><div class="post"><font color="#ff8000">User (enter): 21:42</font></div><div class="post">You have connected to an <a href="http://www.openrpg.com">OpenRPG</a> server, version '1.8.0', named 'Example'.<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
3
+ <html>
4
+
5
+ <table cellspacing=3 cellpadding=4 width="100%">
6
+ <tr>
7
+ <td bgcolor="#101010" align="bottom">
8
+ <center></center>
9
+ </td>
10
+ </tr>
11
+ <tr>
12
+ <td bgcolor="#73A183" align="center">
13
+ <table cellpadding="0" cellspacing="0" width="100%">
14
+ <tr>
15
+ <td align="center" width="100%">
16
+ <h3>Welcome to Example!</h3>
17
+ </td>
18
+ </tr>
19
+ <tr>
20
+ <td align="center" width="100%">
21
+ Please stay a while.
22
+ </td>
23
+ </tr>
24
+ </table>
25
+ </td>
26
+ </tr>
27
+ </table><!-- Created: Thursday November 9 23:55:12 PDT 2003 -->
28
+
29
+ </div><div class="post"><font color="#ff8000">Moving to room 'Test room'..</font></div><div class="post"><font color="#ff8000">User (enter): 21:42</font></div><div class="post"><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
30
+ <html>
31
+
32
+ <table cellspacing=3 cellpadding=4 width="100%">
33
+ <tr>
34
+ <td bgcolor="#101010" align="bottom">
35
+ <center></center>
36
+ </td>
37
+ </tr>
38
+ <tr>
39
+ <td bgcolor="#73A183" align="center">
40
+ <table cellpadding="0" cellspacing="0" width="100%">
41
+ <tr>
42
+ <td align="center" width="100%">
43
+ <h3>Welcome to Example!</h3>
44
+ </td>
45
+ </tr>
46
+ <tr>
47
+ <td align="center" width="100%">
48
+ Please stay a while.
49
+ </td>
50
+ </tr>
51
+ </table>
52
+ </td>
53
+ </tr>
54
+ </table><!-- Created: Thursday November 9 23:55:12 PDT 2003 -->
55
+
56
+ </div><div class="post"><b>User</b>: <font color="#004000">say something</font></div><div class="post"><font color="#004040">** User <font color="#004040">emote something</font> **</font></div><div class="post"><b>User</b>: <font color="#004000">(( say something ))</font></div><div class="post"><font color="#ff8000">Moving to room 'Lobby'..</font></div><div class="post"><font color="#ff8000">User (enter): 21:42</font></div><div class="post"><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
57
+ <html>
58
+
59
+ <table cellspacing=3 cellpadding=4 width="100%">
60
+ <tr>
61
+ <td bgcolor="#101010" align="bottom">
62
+ <center></center>
63
+ </td>
64
+ </tr>
65
+ <tr>
66
+ <td bgcolor="#73A183" align="center">
67
+ <table cellpadding="0" cellspacing="0" width="100%">
68
+ <tr>
69
+ <td align="center" width="100%">
70
+ <h3>Welcome to Example!</h3>
71
+ </td>
72
+ </tr>
73
+ <tr>
74
+ <td align="center" width="100%">
75
+ Please stay a while.
76
+ </td>
77
+ </tr>
78
+ </table>
79
+ </td>
80
+ </tr>
81
+ </table><!-- Created: Thursday November 9 23:55:12 PDT 2003 -->
82
+
83
+ </div><div class="post"><font color="#ff0000">Disconnecting from server...</font></div><div class="post"><font color="#ff0000">Game disconnected!</font></div></body></html>
@@ -0,0 +1,35 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html>
3
+ <head>
4
+ <style type='text/css'>
5
+ body { text-align: center; }
6
+ #container { max-width: 50em; margin: 4em auto; text-align: left; }
7
+ #container h2 { text-align: center; }
8
+ dt.say { font-weight: bold; }
9
+ dt.emote { font-weight: bold; font-style:italic; }
10
+ dd.emote { font-style:italic; }
11
+ .ooc { display: none; }
12
+ dt { width: 7.5em; float: left; text-align: right; }
13
+ dd { margin-left: 0em; padding-left: 8em; margin-bottom: 0.5em; min-height: 2em }
14
+
15
+ </style>
16
+ </head>
17
+ <body>
18
+ <div id='container'>
19
+ <dl>
20
+ <dt class='say'>User</dt>
21
+ <dd class='say' style='color: #004000;' >
22
+ say something
23
+ </dd>
24
+ <dt class='emote'>User</dt>
25
+ <dd class='emote' style='color: #004040;' >
26
+ emote something
27
+ </dd>
28
+ <dt class='ooc'>User</dt>
29
+ <dd class='ooc' style='color: #004000;' >
30
+ (( say something ))
31
+ </dd>
32
+ </dl>
33
+ </div>
34
+ </body>
35
+ </html>
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/ruby
2
+ # Jonathan D. Stott <jonathan.stott@gmail.com>
3
+ require 'spec_helper'
4
+ require 'openlogcleaner/html_document'
5
+
6
+ def parse_file(file)
7
+ @log = OpenLogCleaner::HtmlDocument.new
8
+ @log.add_file(file)
9
+ @log
10
+ end
11
+
12
+ shared "OpenLogCleaner::HtmlDocument" do
13
+ it "doesn't raise an error" do
14
+ lambda { parse_file(@file) }.should.not.raise
15
+ end
16
+
17
+ it "has three lines" do
18
+ parse_file(@file)
19
+ @log.messages.size.should == 3
20
+ end
21
+
22
+ describe "the first line" do
23
+ before do
24
+ @log = parse_file(@file)
25
+ @line = @log.messages.first
26
+ end
27
+
28
+ it "is a say" do
29
+ @line.should.be.is_a(OpenLogCleaner::Say)
30
+ end
31
+
32
+ it "is by 'User'" do
33
+ @line.nick.should == 'User'
34
+ end
35
+
36
+ it "has the content 'say something'" do
37
+ @line.content.should == 'say something'
38
+ end
39
+
40
+ it "is not ooc" do
41
+ @line.should.not.be.is_ooc?
42
+ end
43
+
44
+ it "has the colour #004000" do
45
+ @line.color.should == '#004000'
46
+ end
47
+ end
48
+ describe "the second line" do
49
+ before do
50
+ @log = parse_file(@file)
51
+ @line = @log.messages[1]
52
+ end
53
+
54
+ it "is a say" do
55
+ @line.should.be.is_a(OpenLogCleaner::Emote)
56
+ end
57
+
58
+ it "is by 'User'" do
59
+ @line.nick.should == 'User'
60
+ end
61
+
62
+ it "has the content 'emote something'" do
63
+ @line.content.should == 'emote something'
64
+ end
65
+
66
+ it "is not ooc" do
67
+ @line.should.not.be.is_ooc?
68
+ end
69
+ end
70
+ describe "the third line" do
71
+ before do
72
+ @log = parse_file(@file)
73
+ @line = @log.messages[2]
74
+ end
75
+
76
+ it "is a say" do
77
+ @line.should.be.is_a(OpenLogCleaner::Say)
78
+ end
79
+
80
+ it "is by 'User'" do
81
+ @line.nick.should == 'User'
82
+ end
83
+
84
+ it "has the content 'say something'" do
85
+ @line.content.should == '(( say something ))'
86
+ end
87
+
88
+ it "is ooc" do
89
+ @line.should.be.is_ooc?
90
+ end
91
+ it "has the colour #004000" do
92
+ @line.color.should == '#004000'
93
+ end
94
+ end
95
+ end
96
+
97
+ describe "manual log 1" do
98
+ before do
99
+ @file = "spec/fixtures/manual_testlog.htm"
100
+ end
101
+ behaves_like "OpenLogCleaner::HtmlDocument"
102
+ end
103
+
104
+ describe "manual log 2" do
105
+ before do
106
+ @file = "spec/fixtures/manual2_testlog.htm"
107
+ end
108
+ behaves_like "OpenLogCleaner::HtmlDocument"
109
+ end
110
+
111
+ describe "parsed log" do
112
+ before do
113
+ @file = "spec/fixtures/parsed_testlog.htm"
114
+ end
115
+ behaves_like "OpenLogCleaner::HtmlDocument"
116
+ end
@@ -1,7 +1,2 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Openlogcleaner" do
4
- it "fails" do
5
- should.flunk "hey buddy, you should probably rename this file and start specing for real"
6
- end
7
- end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: openlogcleaner
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jonathan Stott
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-13 00:00:00 +00:00
13
+ date: 2011-02-15 00:00:00 +00:00
14
14
  default_executable: openlogcleaner
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -90,6 +90,10 @@ files:
90
90
  - lib/openlogcleaner/templates/dokuwiki_formatter.mustache
91
91
  - lib/openlogcleaner/templates/html_formatter.mustache
92
92
  - openlogcleaner.gemspec
93
+ - spec/fixtures/manual2_testlog.htm
94
+ - spec/fixtures/manual_testlog.htm
95
+ - spec/fixtures/parsed_testlog.htm
96
+ - spec/openlogcleaner/html_document_spec.rb
93
97
  - spec/openlogcleaner_spec.rb
94
98
  - spec/spec_helper.rb
95
99
  has_rdoc: true
@@ -121,5 +125,6 @@ signing_key:
121
125
  specification_version: 3
122
126
  summary: Cleans OpenRPG logs
123
127
  test_files:
128
+ - spec/openlogcleaner/html_document_spec.rb
124
129
  - spec/openlogcleaner_spec.rb
125
130
  - spec/spec_helper.rb