Class: TF2LineParser::Events::Event

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#airshotObject

Returns the value of attribute airshot.



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

def airshot
  @airshot
end

#cap_nameObject

Returns the value of attribute cap_name.



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

def cap_name
  @cap_name
end

#cap_numberObject

Returns the value of attribute cap_number.



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

def cap_number
  @cap_number
end

#customkillObject

Returns the value of attribute customkill.



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

def customkill
  @customkill
end

#healingObject

Returns the value of attribute healing.



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

def healing
  @healing
end

#itemObject

Returns the value of attribute item.



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

def item
  @item
end

#lengthObject

Returns the value of attribute length.



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

def length
  @length
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

#methodObject

Returns the value of attribute method.



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

def method
  @method
end

#playerObject

Returns the value of attribute player.



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

def player
  @player
end

#roleObject

Returns the value of attribute role.



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

def role
  @role
end

#scoreObject

Returns the value of attribute score.



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

def score
  @score
end

#targetObject

Returns the value of attribute target.



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

def target
  @target
end

#teamObject

Returns the value of attribute team.



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

def team
  @team
end

#timeObject

Returns the value of attribute time.



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

def time
  @time
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#uberchargeObject

Returns the value of attribute ubercharge.



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

def ubercharge
  @ubercharge
end

#unknownObject

Returns the value of attribute unknown.



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

def unknown
  @unknown
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

#weaponObject

Returns the value of attribute weapon.



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

def weapon
  @weapon
end

Class Method Details

.parse_player_section(section) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/tf2_line_parser/events/event.rb', line 72

def self.parse_player_section(section)
  return [nil, nil, nil, nil] unless section

  # Find all <...> groups in the section
  parts = section.scan(/<([^>]*)>/)
  return [nil, nil, nil, nil] if parts.length < 2

  # For the cheeky name tests, we need to find the last complete set of uid/steamid/team
  # Look for the pattern: <uid><steamid><team> at the end
  if parts.length >= 3
    # Try to find the last complete set of 3 groups
    # Start from the end and work backwards
    last_valid_set = nil
    (parts.length - 2).downto(0) do |i|
      if i + 2 < parts.length
        uid = parts[i][0]
        steamid = parts[i + 1][0]
        team = parts[i + 2][0]

        # Check if this looks like a valid set (uid is numeric, steamid looks like steam id, team is valid)
        if uid.match?(/^\d+$/) && (steamid.start_with?('STEAM_') || steamid.start_with?('[U:')) && ['Red', 'Blue', 'Unassigned', 'Spectator', ''].include?(team)
          # This looks like a valid player info set
          last_valid_set = [i, uid, steamid, team]
          break  # Take the last (rightmost) valid set
        end
      end
    end

    if last_valid_set
      i, uid, steamid, team = last_valid_set
      # The name is everything before the first <...> group of this set
      uid_start = section.index("<#{uid}>")
      if uid_start
        name = section[0...uid_start]
        return [name, uid, steamid, team]
      end
    end
  end

  # Handle cases with 2 or 3 groups (normal case)
  if parts.length == 2
    # Only uid and steamid, no team
    uid = parts[0][0]
    steamid = parts[1][0]
    team = ""
  else
    # uid, steamid, and team
    uid = parts[-3][0]
    steamid = parts[-2][0]
    team = parts[-1][0]
  end

  # The name is everything before the first <...> group
  name_end = section.index("<#{uid}>")
  return [nil, nil, nil, nil] unless name_end

  name = section[0...name_end]

  [name, uid, steamid, team]
end

.parse_target_section(section) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/tf2_line_parser/events/event.rb', line 133

def self.parse_target_section(section)
  return [nil, nil, nil, nil] unless section

  # Same logic as player but for targets
  parts = section.scan(/<([^>]*)>/)
  return [nil, nil, nil, nil] if parts.length < 2

  # Handle cases with 2 or 3 groups
  if parts.length == 2
    # Only uid and steamid, no team
    uid = parts[0][0]
    steamid = parts[1][0]
    team = ""
  else
    # uid, steamid, and team
    uid = parts[-3][0]
    steamid = parts[-2][0]
    team = parts[-1][0]
  end

  # The name is everything before the first <...> group
  name_end = section.index("<#{uid}>")
  return [nil, nil, nil, nil] unless name_end

  name = section[0...name_end]

  [name, uid, steamid, team]
end

.regex_capObject



25
26
27
# File 'lib/tf2_line_parser/events/event.rb', line 25

def self.regex_cap
  @regex_cap ||= '\(cp "(?\'cp_number\'\d+)"\) \(cpname "(?\'cp_name\'[^"]*)"'
end

.regex_consoleObject



29
30
31
# File 'lib/tf2_line_parser/events/event.rb', line 29

def self.regex_console
  @regex_console ||= '"Console<0><Console><Console>"'
end

.regex_messageObject



33
34
35
# File 'lib/tf2_line_parser/events/event.rb', line 33

def self.regex_message
  @regex_message ||= '"(?\'message\'.*)"'
end

.regex_playerObject



17
18
19
# File 'lib/tf2_line_parser/events/event.rb', line 17

def self.regex_player
  @regex_player ||= /"(?<player_section>.*?)"/
end

.regex_results(matched_line) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/tf2_line_parser/events/event.rb', line 45

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 :target_section
      if matched_line['target_section']
        out.concat(parse_target_section(matched_line['target_section']))
      else
        out.concat([nil, nil, nil, nil])
      end
    else
      out << matched_line[attribute]
    end
  end
  out
end

.regex_targetObject



21
22
23
# File 'lib/tf2_line_parser/events/event.rb', line 21

def self.regex_target
  @regex_target ||= /"(?<target_section>.*?)"/
end

.regex_timeObject



13
14
15
# File 'lib/tf2_line_parser/events/event.rb', line 13

def self.regex_time
  @regex_time ||= 'L (?\'time\'\\d{2}/\\d{2}/\\d{4} - \\d{2}:\\d{2}:\\d{2}):'
end

.time_formatObject



9
10
11
# File 'lib/tf2_line_parser/events/event.rb', line 9

def self.time_format
  @time_format ||= '%m/%d/%Y - %T'
end

Instance Method Details

#parse_time(time_string) ⇒ Object



68
69
70
# File 'lib/tf2_line_parser/events/event.rb', line 68

def parse_time(time_string)
  Time.strptime(time_string, Event.time_format)
end