openlogcleaner 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.22
1
+ 0.0.23
@@ -22,28 +22,47 @@ module OpenLogCleaner
22
22
  end
23
23
 
24
24
  def add_messages(doc)
25
- doc.css('div').each do |msg|
26
- begin
27
- case msg['class']
28
- when 'post'
29
- add_post(msg)
30
- when 'emote'
31
- add_emote(msg)
32
- when 'info', 'system'
33
- next
34
- else
35
- # warn about an unknown div, unless it's the container div, which is
36
- # element conversations get wrapped in by this code.
37
- # This allows multiple passes, should this code be updated.
38
- raise "Unknown div class '#{msg['class']}'" unless msg['id'] == 'container'
25
+ if (dl = doc.at('dl'))
26
+ elements = dl.children.to_a
27
+ elements.delete_if { |elem| Nokogiri::XML::Text === elem }
28
+ until elements.empty?
29
+ dt, dd = elements.shift, elements.shift
30
+ add_list_entry(dt, dd)
31
+ end
32
+ else
33
+ doc.css('div').each do |msg|
34
+ begin
35
+ case msg['class']
36
+ when 'post'
37
+ add_post(msg)
38
+ when 'emote'
39
+ add_emote(msg)
40
+ when 'info', 'system'
41
+ next
42
+ else
43
+ # warn about an unknown div, unless it's the container div, which is
44
+ # element conversations get wrapped in by this code.
45
+ # This allows multiple passes, should this code be updated.
46
+ raise "Unknown div class '#{msg['class']}'" unless msg['id'] == 'container'
47
+ end
48
+ rescue Exception => e
49
+ warn msg.inspect
50
+ raise e
39
51
  end
40
- rescue Exception => e
41
- warn msg.inspect
42
- raise e
43
52
  end
44
53
  end
45
54
  end
46
55
 
56
+ def add_list_entry(dt, dd)
57
+ name = dt.inner_text
58
+ if dt[:style] =~ /color: #([a-f0-9]{6});/i
59
+ color = $1
60
+ end
61
+ 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
+ end
65
+
47
66
  def add_post(msg)
48
67
  return if msg.children.first.name == 'font' # deal with system messages
49
68
  return if msg.at('table') # deal with welcome messages
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{openlogcleaner}
8
- s.version = "0.0.22"
8
+ s.version = "0.0.23"
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"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: openlogcleaner
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.22
5
+ version: 0.0.23
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jonathan Stott