tf2_line_parser 0.5.0 → 0.5.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c1d38c81d58d2ecb10aa612b2602de4abf47b540ec3caf003273a87cdcdb5ba
4
- data.tar.gz: 7993c5640a38063e5082780475881b1faca2898a5f6555ac4040ff612f341f2c
3
+ metadata.gz: ce1e976cd8122572fc3e7ca491e66064e93a6bf46153c1d8fbc3d47961c1df22
4
+ data.tar.gz: d6cc774e17ab02595f7253e31ed9f436dc163681fd82ca2385d5118d80c5c639
5
5
  SHA512:
6
- metadata.gz: 41f0d0adece361d3e97a3ec48466dd8123fdc95d8ea26f5616f57f125426225a36f6dfc2d1a5611115993863980d2d18e08d49f46397bba71dbe8775f0c7ef65
7
- data.tar.gz: 872376b6810e9d6031cbd0d6cf38156ef99fba2dbf91174761c354a44fa040f9d7809bb5736518406bccdecbfb1f3a3f1314f6c54be14000a88af223a2287ee0
6
+ metadata.gz: 0bd2e58a37355dc74faf0f3b3db946e13cf273453d9ed46e6073fd3a15585ecdecfce3caf54279303a16f004141bcb7509d4ece264c82f09e16c3def603b24a7
7
+ data.tar.gz: 74717248ec519c02913b20bb6b4565b147a7b6aa11a211f78917756ab9696a3620eb98ec4c0347988d2a39feed30cc6cf42c2653857665ee871e7f68f0d11eb3
data/.tool-versions ADDED
@@ -0,0 +1,2 @@
1
+ ruby 4.0.0
2
+ nodejs latest
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # TF2 line parser [![Build Status](https://travis-ci.org/Arie/tf2_line_parser.png?branch=master)](http://travis-ci.org/Arie/tf2_line_parser) [![Dependency Status](https://gemnasium.com/Arie/tf2_line_parser.png)](https://gemnasium.com/Arie/tf2_line_parser) [![Code Climate](https://codeclimate.com/github/Arie/tf2_line_parser.png)](https://codeclimate.com/github/Arie/tf2_line_parser) [![Coverage Status](https://coveralls.io/repos/Arie/tf2_line_parser/badge.png?branch=master)](https://coveralls.io/r/Arie/tf2_line_parser)
1
+ # TF2 line parser
2
2
 
3
3
  A TF2 log line parser. Unlike the other log parsers I've found, this one parses the line and returns a plain old ruby object to describe the event of the line.
4
4
  I plan to use this for my own stats parsing tool.
5
5
 
6
6
  ## Requirements
7
- * Ruby
7
+ * Ruby (no runtime dependencies)
8
8
 
9
9
  ## Credits
10
10
  * nTraum, I stole most of the regexes from his [TF2Stats](https://github.com/nTraum/tf2stats/) project.
@@ -38,7 +38,7 @@ module TF2LineParser
38
38
  # ordered by how common the messages are
39
39
  @types ||= [ShotFired, ShotHit, PositionReport, HeadshotDamage, Airshot, Damage, AirshotHeal, Heal, PickupItem, Assist, Kill, CaptureBlock, PointCapture, ChargeDeployed,
40
40
  MedicDeath, MedicDeathEx, EmptyUber, ChargeReady, ChargeEnded, FirstHealAfterSpawn, LostUberAdvantage, BuiltObject, PlayerExtinguished, JoinedTeam, EnteredGame, RoleChange, Spawn, Suicide, KilledObject, Say, TeamSay, Domination, Revenge, RoundWin, CurrentScore,
41
- RoundLength, RoundStart, RoundSetupBegin, RoundSetupEnd, MiniRoundStart, MiniRoundSelected, IntermissionWinLimit, Connect, Disconnect, RconCommand, ConsoleSay, MatchEnd, FinalScore,
41
+ RoundLength, RoundStart, RoundSetupBegin, RoundSetupEnd, MiniRoundStart, MiniRoundSelected, WorldIntermissionWinLimit, IntermissionWinLimit, Connect, Disconnect, RconCommand, ConsoleSay, MatchEnd, FinalScore,
42
42
  RoundStalemate, Unknown].freeze
43
43
  end
44
44
 
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TF2LineParser
4
+ module Events
5
+ class WorldIntermissionWinLimit < RoundEventWithoutVariables
6
+ def self.round_type
7
+ @round_type ||= 'Intermission_Win_Limit'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -10,8 +10,8 @@ module TF2LineParser
10
10
  KEYWORD_DISPATCH = {
11
11
  'shot_fired' => [Events::ShotFired],
12
12
  'shot_hit' => [Events::ShotHit],
13
- 'damage' => [Events::HeadshotDamage, Events::Airshot, Events::Damage],
14
- 'healed' => [Events::AirshotHeal, Events::Heal],
13
+ 'damage' => :check_damage_subtypes,
14
+ 'healed' => :check_heal_subtypes,
15
15
  'picked up' => [Events::PickupItem],
16
16
  'kill assist' => [Events::Assist],
17
17
  'killed' => [Events::Kill],
@@ -43,7 +43,7 @@ module TF2LineParser
43
43
  'Round_Setup_End' => [Events::RoundSetupEnd],
44
44
  'Mini_Round_Start' => [Events::MiniRoundStart],
45
45
  'Mini_Round_Selected' => [Events::MiniRoundSelected],
46
- 'Intermission_Win_Limit' => [Events::IntermissionWinLimit],
46
+ 'Intermission_Win_Limit' => [Events::WorldIntermissionWinLimit, Events::IntermissionWinLimit],
47
47
  'Round_Stalemate' => [Events::RoundStalemate],
48
48
  'Game_Over' => [Events::MatchEnd],
49
49
  'connected, address' => [Events::Connect],
@@ -70,7 +70,13 @@ module TF2LineParser
70
70
  # Class method to parse without object allocation
71
71
  def self.parse(line)
72
72
  types = find_candidate_types(line)
73
- try_parse_types(line, types)
73
+ result = try_parse_types(line, types)
74
+ return result if result
75
+
76
+ # If candidate types didn't match, fall back to Unknown (unless we already tried fallbacks)
77
+ return nil if types == FALLBACK_TYPES
78
+
79
+ try_parse_types(line, [Events::Unknown])
74
80
  end
75
81
 
76
82
  class << self
@@ -84,8 +90,17 @@ module TF2LineParser
84
90
  end_idx = line.index('"', start_idx + 11)
85
91
  if end_idx
86
92
  keyword = line[start_idx + 11...end_idx]
87
- types = KEYWORD_DISPATCH[keyword]
88
- return types if types
93
+ result = KEYWORD_DISPATCH[keyword]
94
+ if result
95
+ case result
96
+ when :check_damage_subtypes
97
+ return check_damage_subtypes(line)
98
+ when :check_heal_subtypes
99
+ return check_heal_subtypes(line)
100
+ else
101
+ return result
102
+ end
103
+ end
89
104
  end
90
105
  end
91
106
  end
@@ -133,6 +148,32 @@ module TF2LineParser
133
148
  end
134
149
  nil
135
150
  end
151
+
152
+ def check_damage_subtypes(line)
153
+ damage_attr_pos = line.index('(damage "')
154
+ return [Events::Damage] unless damage_attr_pos
155
+
156
+ suffix = line[damage_attr_pos..-1]
157
+ if suffix.include?('(headshot "')
158
+ [Events::HeadshotDamage]
159
+ elsif suffix.include?('(airshot "')
160
+ [Events::Airshot]
161
+ else
162
+ [Events::Damage]
163
+ end
164
+ end
165
+
166
+ def check_heal_subtypes(line)
167
+ heal_attr_pos = line.index('(healing "')
168
+ return [Events::Heal] unless heal_attr_pos
169
+
170
+ suffix = line[heal_attr_pos..-1]
171
+ if suffix.include?('(airshot "')
172
+ [Events::AirshotHeal]
173
+ else
174
+ [Events::Heal]
175
+ end
176
+ end
136
177
  end
137
178
  end
138
179
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TF2LineParser
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
@@ -456,6 +456,12 @@ module TF2LineParser
456
456
  parse(line)
457
457
  end
458
458
 
459
+ it 'recognizes world intermission win limit' do
460
+ line = 'L 01/24/2026 - 15:30:45: World triggered "Intermission_Win_Limit"'
461
+ expect(Events::WorldIntermissionWinLimit).to receive(:new).with(anything)
462
+ parse(line)
463
+ end
464
+
459
465
  it 'recognizes ubercharges' do
460
466
  line = log_lines[1416]
461
467
  name = 'broder mirelin'
@@ -731,6 +737,16 @@ module TF2LineParser
731
737
  parse(line)
732
738
  end
733
739
 
740
+ it 'falls back to Unknown when keyword matches but regex does not' do
741
+ # A triggered event with a recognized keyword but unrecognized format should
742
+ # fall back to Unknown instead of returning nil
743
+ line = 'L 01/24/2026 - 15:30:45: Something triggered "Round_Win" with unexpected format'
744
+ time = '01/24/2026 - 15:30:45'
745
+ unknown = 'Something triggered "Round_Win" with unexpected format'
746
+ expect(Events::Unknown).to receive(:new).with(time, unknown)
747
+ parse(line)
748
+ end
749
+
734
750
  it 'can parse all lines in the example log files without exploding' do
735
751
  broder_vs_epsilon = File.expand_path('../../fixtures/logs/broder_vs_epsilon.log', __dir__)
736
752
  special_characters = File.expand_path('../../fixtures/logs/special_characters.log', __dir__)
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tf2_line_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arie
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-12-31 00:00:00.000000000 Z
10
+ date: 2026-01-24 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: coveralls_reborn
@@ -75,6 +74,7 @@ files:
75
74
  - ".coverage"
76
75
  - ".gitignore"
77
76
  - ".rspec"
77
+ - ".tool-versions"
78
78
  - ".travis.yml"
79
79
  - Gemfile
80
80
  - Gemfile.lock
@@ -135,6 +135,7 @@ files:
135
135
  - lib/tf2_line_parser/events/spawn.rb
136
136
  - lib/tf2_line_parser/events/suicide.rb
137
137
  - lib/tf2_line_parser/events/unknown.rb
138
+ - lib/tf2_line_parser/events/world_intermission_win_limit.rb
138
139
  - lib/tf2_line_parser/line.rb
139
140
  - lib/tf2_line_parser/parser.rb
140
141
  - lib/tf2_line_parser/player.rb
@@ -156,7 +157,6 @@ files:
156
157
  homepage: http://github.com/Arie/tf2_line_parser
157
158
  licenses: []
158
159
  metadata: {}
159
- post_install_message:
160
160
  rdoc_options: []
161
161
  require_paths:
162
162
  - lib
@@ -171,8 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  requirements: []
174
- rubygems_version: 3.5.11
175
- signing_key:
174
+ rubygems_version: 4.0.3
176
175
  specification_version: 4
177
176
  summary: TF2 log line parser
178
177
  test_files: