Class: TF2LineParser::Line

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

Constant Summary collapse

KEYWORD_DISPATCH =

Keyword to event types mapping (order matters for subtypes!)

{
  'shot_fired' => [Events::ShotFired],
  'shot_hit' => [Events::ShotHit],
  'damage' => :check_damage_subtypes,
  'healed' => :check_heal_subtypes,
  'picked up' => [Events::PickupItem],
  'kill assist' => [Events::Assist],
  'killed' => [Events::Kill],
  'killedobject' => [Events::KilledObject],
  'captureblocked' => [Events::CaptureBlock],
  'pointcaptured' => [Events::PointCapture],
  'chargedeployed' => [Events::ChargeDeployed],
  'medic_death_ex' => [Events::MedicDeathEx],
  'medic_death' => [Events::MedicDeath],
  'empty_uber' => [Events::EmptyUber],
  'chargeready' => [Events::ChargeReady],
  'chargeended' => [Events::ChargeEnded],
  'first_heal_after_spawn' => [Events::FirstHealAfterSpawn],
  'lost_uber_advantage' => [Events::LostUberAdvantage],
  'builtobject' => [Events::BuiltObject],
  'player_builtobject' => [Events::BuiltObject],
  'player_extinguished' => [Events::PlayerExtinguished],
  'joined team' => [Events::JoinedTeam],
  'entered the game' => [Events::EnteredGame],
  'changed role' => [Events::RoleChange],
  'spawned as' => [Events::Spawn],
  'committed suicide' => [Events::Suicide],
  'domination' => [Events::Domination],
  'revenge' => [Events::Revenge],
  'Round_Win' => [Events::RoundWin],
  'Round_Length' => [Events::RoundLength],
  'Round_Start' => [Events::RoundStart],
  'Round_Setup_Begin' => [Events::RoundSetupBegin],
  'Round_Setup_End' => [Events::RoundSetupEnd],
  'Mini_Round_Start' => [Events::MiniRoundStart],
  'Mini_Round_Selected' => [Events::MiniRoundSelected],
  'Mini_Round_Length' => [Events::MiniRoundLength],
  'Mini_Round_Win' => [Events::MiniRoundWin],
  'Intermission_Win_Limit' => [Events::WorldIntermissionWinLimit, Events::IntermissionWinLimit],
  'Round_Stalemate' => [Events::RoundStalemate],
  'Game_Over' => [Events::MatchEnd],
  'connected, address' => [Events::Connect],
  'disconnected' => [Events::Disconnect],
  'say_team' => [Events::TeamSay],
  'say "' => [Events::Say],
  'position_report' => [Events::PositionReport],
}.freeze
FALLBACK_TYPES =

Fallback types when no keyword matches - ordered by specificity

[
  Events::FeignDeath, Events::Kill, Events::PositionReport,
  Events::TeamSay, Events::Say, Events::PickupItem,
  Events::JoinedTeam, Events::EnteredGame, Events::RoleChange,
  Events::Spawn, Events::Suicide, Events::Connect, Events::Disconnect,
  Events::CurrentScore, Events::FinalScore, Events::RconCommand,
  Events::ConsoleSay, Events::Unknown
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ Line

Returns a new instance of Line.



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

def initialize(line)
  @line = line
end

Instance Attribute Details

#lineObject

Returns the value of attribute line.



7
8
9
# File 'lib/tf2_line_parser/line.rb', line 7

def line
  @line
end

Class Method Details

.parse(line) ⇒ Object

Class method to parse without object allocation



77
78
79
80
81
82
83
84
85
86
# File 'lib/tf2_line_parser/line.rb', line 77

def self.parse(line)
  types = find_candidate_types(line)
  result = try_parse_types(line, types)
  return result if result

  # If candidate types didn't match, fall back to Unknown (unless we already tried fallbacks)
  return nil if types == FALLBACK_TYPES

  try_parse_types(line, [Events::Unknown])
end

Instance Method Details

#parseObject



72
73
74
# File 'lib/tf2_line_parser/line.rb', line 72

def parse
  self.class.parse(@line)
end