regulos 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,9 @@
1
+ #### v0.2.0
2
+ * Add basic event filtering
3
+
1
4
  #### v0.1.1
2
5
  * Add more tests
3
6
  * Fix event determination for deaths
7
+
4
8
  #### v0.1.0
5
9
  * Initial parser
data/README.md CHANGED
@@ -12,7 +12,9 @@
12
12
 
13
13
  * require 'regulos'
14
14
  * log = Regulos::CombatLog.parse "/path/to/combatlog.txt"
15
- * log.events
15
+ * log.filter :only => {:event => ["Heal"]
16
+ * events = log.filter :exclude => {:event => ["Heal", "CriticalHeal"]
17
+ * events.first.full_message
16
18
 
17
19
 
18
20
  #### Methods on Event
@@ -2,4 +2,5 @@ lib = File.expand_path('../', __FILE__)
2
2
  $:.unshift lib unless $:.include?(lib)
3
3
 
4
4
  require "regulos/combat_log/file.rb"
5
+ require "regulos/combat_log/event_collection.rb"
5
6
  require "regulos/combat_log/event.rb"
@@ -1,3 +1,5 @@
1
+ require "digest/md5"
2
+
1
3
  module Regulos
2
4
  module CombatLog
3
5
  module Event
@@ -10,8 +12,8 @@ module Regulos
10
12
  :Heal => "5",
11
13
  :BuffGain => "6",
12
14
  :BuffFade => "7",
13
- :Affliction => "8",
14
- :Dissipate => "9",
15
+ :DebuffGain => "8",
16
+ :DebuffFade => "9",
15
17
  :AttackMiss => "10",
16
18
  :Death => "11",
17
19
  :UnknownDeath => "12",
@@ -34,7 +36,19 @@ module Regulos
34
36
  end
35
37
 
36
38
  def inspect
37
- "<#{self.class}>"
39
+ "<#{self.class} id=#{id}>"
40
+ end
41
+
42
+ def id
43
+ @id ||= Digest::MD5.hexdigest( [time, full_message].join ) if time && full_message
44
+ end
45
+
46
+ def ==(other)
47
+ other.id == id
48
+ end
49
+
50
+ def name
51
+ self.class.to_s.split("::").last
38
52
  end
39
53
 
40
54
  def code
@@ -50,11 +64,11 @@ module Regulos
50
64
  end
51
65
 
52
66
  def buff?
53
- code == :BuffGain
67
+ code == :BuffGain || code == :BuffFade
54
68
  end
55
69
 
56
70
  def debuff?
57
- code == :Affliction
71
+ code == :DebuffGain || code == :DebuffFade
58
72
  end
59
73
 
60
74
  def process attributes
@@ -1,7 +1,7 @@
1
1
  module Regulos
2
2
  module CombatLog
3
3
  module Event
4
- class Affliction < Base
4
+ class DebuffFade < Base
5
5
  end
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module Regulos
2
2
  module CombatLog
3
3
  module Event
4
- class Dissipate < Base
4
+ class DebuffGain < Base
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,45 @@
1
+ require "delegate"
2
+ module Regulos
3
+ module CombatLog
4
+ class EventCollection < Array
5
+ class FilterException < RuntimeError;end
6
+
7
+ attr_reader :events
8
+
9
+ def initialize(events=[])
10
+ @events = events
11
+ super(@events)
12
+ end
13
+
14
+ def inspect
15
+ "<#{self.class} size=#{size}"
16
+ end
17
+
18
+ # Search the collection
19
+ # e.g. :only => {:event => ["Heal", "BuffGain"]}
20
+ # e.g. :only => {:target => [:player]} #NYI
21
+ def filter(options={})
22
+ if options[:only] && options[:exclude]
23
+ raise FilterException, "You can't specify both 'only' and 'exclude'."
24
+ end
25
+
26
+ return only(options[:only]) if options[:only]
27
+ return exclude(options[:exclude]) if options[:exclude]
28
+ end
29
+
30
+ protected
31
+ def only(options)
32
+ filter_events(:only, options[:event]) if options[:event]
33
+ end
34
+
35
+ def exclude(options)
36
+ filter_events(:exclude, options[:event]) if options[:event]
37
+ end
38
+
39
+ def filter_events mode, keys
40
+ mode = mode == :only ? :select : :reject
41
+ EventCollection.new send(mode){|e| keys.include?(e.name) }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -13,7 +13,7 @@ module Regulos
13
13
  attr_reader :path, :events
14
14
  def initialize(options={})
15
15
  @path = ::File.exist?( options[:path] ) ? options[:path] : raise(FileNotFoundError, "The specified combat log does not exist.")
16
- @events = []
16
+ @events = EventCollection.new []
17
17
  end
18
18
 
19
19
  def parse
@@ -21,6 +21,10 @@ module Regulos
21
21
  data.each{|row| @events << Event.handle(row) }
22
22
  end
23
23
 
24
+ def filter options
25
+ events.filter(options)
26
+ end
27
+
24
28
  def inspect
25
29
  "<Regulos::CombatLog::File path=#{@path}>"
26
30
  end
@@ -1,7 +1,7 @@
1
1
  module Regulos
2
2
  MAJOR_VERSION = "0"
3
- MINOR_VERSION = "1"
4
- BUG_VERSION = "1"
3
+ MINOR_VERSION = "2"
4
+ BUG_VERSION = "0"
5
5
 
6
6
  VERSION = [ MAJOR_VERSION, MINOR_VERSION, BUG_VERSION ].join "."
7
7
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - James Cook
@@ -40,7 +40,6 @@ extensions: []
40
40
  extra_rdoc_files: []
41
41
 
42
42
  files:
43
- - lib/regulos/combat_log/event/affliction.rb
44
43
  - lib/regulos/combat_log/event/attack_hit.rb
45
44
  - lib/regulos/combat_log/event/attack_miss.rb
46
45
  - lib/regulos/combat_log/event/base.rb
@@ -52,7 +51,8 @@ files:
52
51
  - lib/regulos/combat_log/event/damage.rb
53
52
  - lib/regulos/combat_log/event/damage_over_time.rb
54
53
  - lib/regulos/combat_log/event/death.rb
55
- - lib/regulos/combat_log/event/dissipate.rb
54
+ - lib/regulos/combat_log/event/debuff_fade.rb
55
+ - lib/regulos/combat_log/event/debuff_gain.rb
56
56
  - lib/regulos/combat_log/event/dodge.rb
57
57
  - lib/regulos/combat_log/event/end_cast.rb
58
58
  - lib/regulos/combat_log/event/fall_damage.rb
@@ -66,6 +66,7 @@ files:
66
66
  - lib/regulos/combat_log/event/unknown.rb
67
67
  - lib/regulos/combat_log/event/unknown_death.rb
68
68
  - lib/regulos/combat_log/event.rb
69
+ - lib/regulos/combat_log/event_collection.rb
69
70
  - lib/regulos/combat_log/file.rb
70
71
  - lib/regulos/version.rb
71
72
  - lib/regulos.rb