Class: Regulos::CombatLog::Event::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/regulos/combat_log/event/base.rb

Overview

An event represents a row in the combat log.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Base

Returns a new instance of Base.



32
33
34
# File 'lib/regulos/combat_log/event/base.rb', line 32

def initialize(attributes)
  process attributes
end

Class Method Details

.determine_event_type(hash) ⇒ Object



101
102
103
104
# File 'lib/regulos/combat_log/event/base.rb', line 101

def determine_event_type hash
  kind = CODES.invert.fetch(hash[:action_code]){ "Unknown" }
  Regulos::CombatLog::Event.const_get "#{kind}"
end

.sanitize(hash) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/regulos/combat_log/event/base.rb', line 89

def sanitize hash
  hash.each_pair do |k,v|
    v.to_s.strip!                # Remove leading space
    v.to_s.gsub! /[,\(\)]\Z/, '' # Then remove leading comma or parenthesis
    v.to_s.gsub! /\A[,\(\)]/, '' # Then remove trailing comma or parenthesis
    v.to_s.strip!                # Then remove trailing space
    hash[k] = v
  end

  hash
end

.which(row) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/regulos/combat_log/event/base.rb', line 67

def which(row)
  require "strscan"
  s = StringScanner.new row   
#03:53:35: ( 15 , T=N#R=O#9223372038886130583 , T=N#R=O#9223372043800556153 , T=X#R=X#224054081475471412 , T=X#R=X#0 , Lesser Earth Elemental , Eternal Servant , 0 , 75533189 , Thud ) Eternal Servant dodges Lesser Earth Elemental's Thud.
  entity_regex  = /\s[A-Z]=[A-Z]#[A-Z]=[A-Z]#\d+?\s,/
  e = {}
  e[:time]         = s.scan(/\d{2}:\d{2}:\d{2}:\s\(/)  # Time of action
  e[:action_code]  = s.scan(/\s\d+?\s,/)               # 15 (dodge)
  e[:origin]       = s.scan entity_regex
  e[:target]       = s.scan entity_regex
  e[:pet_origin]   = s.scan entity_regex               # Your pet did something
  e[:pet_target]   = s.scan entity_regex               # Your pet is receiving damage, heal, etc
  e[:origin_name]  = s.scan /\s[A-Za-z\s\-]+?\s,/
  e[:target_name]  = s.scan /\s[A-Za-z\s\-]+?\s,/
  e[:output]       = s.scan /\s\d+?\s,/                # Damage or healing output
  e[:spell_id]     = s.scan /\s\d+?\s,/                # Spell ID
  e[:spell_name]   = s.scan /\s[A-Za-z\-\s]+?\s\)/     # Spell name
  e[:full_message] = s.scan /\s(.*)+\Z/                # Full log message
  e = sanitize(e)
  determine_event_type(e).new e
end

Instance Method Details

#buff?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/regulos/combat_log/event/base.rb', line 52

def buff?
  code == :BuffGain
end

#codeObject



40
41
42
# File 'lib/regulos/combat_log/event/base.rb', line 40

def code
  CODES.invert[ action_code ]
end

#debuff?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/regulos/combat_log/event/base.rb', line 56

def debuff?
  code == :Affliction
end

#heal?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/regulos/combat_log/event/base.rb', line 44

def heal?
  full_message =~ /heals/
end

#inspectObject



36
37
38
# File 'lib/regulos/combat_log/event/base.rb', line 36

def inspect
  "<#{self.class}>"
end

#overheal?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/regulos/combat_log/event/base.rb', line 48

def overheal?
  full_message =~ /\d\soverheal/
end

#process(attributes) ⇒ Object



60
61
62
# File 'lib/regulos/combat_log/event/base.rb', line 60

def process attributes
  attributes.each_pair{|k,v| self.class.send(:attr_reader, k); instance_variable_set("@#{k}", v) }
end