class Quaker3::Parser

Converts the Quake 3 Arena log file into Game model @author Renan Gigliotti

Constants

COMMAND_INIT_GAME
COMMAND_KILL
COMMAND_SHUTDOWN
REGEX_COMMAND

Attributes

games[R]

List of Game model parsed from Quake 3 Arena Server log file @return [Game] list of games

Public Class Methods

new(file_path) click to toggle source

Initialize method to generate a list of games from Quake 3 Arena Server log file @param file_path [String] the path of file

# File lib/quaker3/parser.rb, line 20
def initialize(file_path)
  @games = []
  @current_game = nil
  process file_path
end

Private Instance Methods

extract_command(line) click to toggle source
# File lib/quaker3/parser.rb, line 37
def extract_command(line)
  line[REGEX_COMMAND].strip.split[1].downcase
end
init_game() click to toggle source
# File lib/quaker3/parser.rb, line 52
def init_game
  @games.push @current_game unless @current_game.nil?
  @current_game = Quaker3::Game.new
  @current_game.id = SecureRandom.uuid
end
kill(line) click to toggle source
# File lib/quaker3/parser.rb, line 63
def kill(line)
  @current_game.kills.push Quaker3::Kill.new(line)
end
parse(command, line) click to toggle source
# File lib/quaker3/parser.rb, line 41
def parse(command, line)
  case command
  when COMMAND_INIT_GAME
    init_game
  when COMMAND_SHUTDOWN
    shutdown
  when COMMAND_KILL
    kill line
  end
end
process(file_path) click to toggle source
# File lib/quaker3/parser.rb, line 28
def process(file_path)
  File.foreach file_path do |line|
    command = extract_command line
    parse command, line
  end

  shutdown
end
shutdown() click to toggle source
# File lib/quaker3/parser.rb, line 58
def shutdown
  @games.push @current_game unless @current_game.nil?
  @current_game = nil
end