Class: TF2LineParser::Events::KilledObject

Inherits:
Event
  • Object
show all
Defined in:
lib/tf2_line_parser/events/killed_object.rb

Instance Attribute Summary collapse

Attributes inherited from Event

#airshot, #cap_name, #cap_number, #customkill, #healing, #item, #length, #message, #method, #role, #score, #target, #team, #type, #ubercharge, #unknown, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Event

parse_player_section, parse_target_section, #parse_time, regex_cap, regex_console, regex_message, regex_player, regex_target, regex_time, time_format, types

Constructor Details

#initialize(time, player_name, player_uid, player_steam_id, player_team, object, weapon, objectowner_name, objectowner_uid, objectowner_steam_id, objectowner_team) ⇒ KilledObject

Returns a new instance of KilledObject.



45
46
47
48
49
50
51
# File 'lib/tf2_line_parser/events/killed_object.rb', line 45

def initialize(time, player_name, player_uid, player_steam_id, player_team, object, weapon, objectowner_name, objectowner_uid, objectowner_steam_id, objectowner_team)
  @time = parse_time(time)
  @player = Player.new(player_name, player_uid, player_steam_id, player_team)
  @object = object
  @weapon = weapon
  @objectowner = Player.new(objectowner_name, objectowner_uid, objectowner_steam_id, objectowner_team)
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



4
5
6
# File 'lib/tf2_line_parser/events/killed_object.rb', line 4

def object
  @object
end

#objectownerObject (readonly)

Returns the value of attribute objectowner.



4
5
6
# File 'lib/tf2_line_parser/events/killed_object.rb', line 4

def objectowner
  @objectowner
end

#playerObject (readonly)

Returns the value of attribute player.



4
5
6
# File 'lib/tf2_line_parser/events/killed_object.rb', line 4

def player
  @player
end

#timeObject (readonly)

Returns the value of attribute time.



4
5
6
# File 'lib/tf2_line_parser/events/killed_object.rb', line 4

def time
  @time
end

#weaponObject (readonly)

Returns the value of attribute weapon.



4
5
6
# File 'lib/tf2_line_parser/events/killed_object.rb', line 4

def weapon
  @weapon
end

Class Method Details

.attributesObject



18
19
20
# File 'lib/tf2_line_parser/events/killed_object.rb', line 18

def self.attributes
  @attributes ||= %i[time player_section object weapon objectowner_section]
end

.regexObject



6
7
8
# File 'lib/tf2_line_parser/events/killed_object.rb', line 6

def self.regex
  @regex ||= /#{regex_time} #{regex_player} triggered "killedobject" #{regex_object_info}#{regex_attacker_position}?/.freeze
end

.regex_attacker_positionObject



14
15
16
# File 'lib/tf2_line_parser/events/killed_object.rb', line 14

def self.regex_attacker_position
  @regex_attacker_position ||= / \(attacker_position "[^"]+"\)/
end

.regex_object_infoObject



10
11
12
# File 'lib/tf2_line_parser/events/killed_object.rb', line 10

def self.regex_object_info
  @regex_object_info ||= '\(object "(?\'object\'[^"]+)"\) \(weapon "(?\'weapon\'[^"]+)"\) \(objectowner "(?\'objectowner_section\'.*?)"\)'
end

.regex_results(matched_line) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tf2_line_parser/events/killed_object.rb', line 22

def self.regex_results(matched_line)
  out = []
  attributes.each do |attribute|
    case attribute
    when :player_section
      if matched_line['player_section']
        out.concat(parse_player_section(matched_line['player_section']))
      else
        out.concat([nil, nil, nil, nil])
      end
    when :objectowner_section
      if matched_line['objectowner_section']
        out.concat(parse_player_section(matched_line['objectowner_section']))
      else
        out.concat([nil, nil, nil, nil])
      end
    else
      out << matched_line[attribute]
    end
  end
  out
end