Class: QuakeLogParser::LogReader

Inherits:
Object
  • Object
show all
Defined in:
lib/quake-log-parser/log_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ LogReader

Returns a new instance of LogReader.



3
4
5
6
# File 'lib/quake-log-parser/log_reader.rb', line 3

def initialize(file_path)
  @file_path = file_path
  @line_handler = QuakeLogParser::LineHandler.new
end

Instance Method Details

#readObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/quake-log-parser/log_reader.rb', line 8

def read
  File.open(@file_path, 'r') do |file|
    file.each_line do |line|
      case line
      when QuakeLogParser::Patterns.new_game
        @line_handler.handle_new_game(line)
      when QuakeLogParser::Patterns.new_player
        @line_handler.handle_new_player(line)
      when QuakeLogParser::Patterns.new_kill
        @line_handler.handle_new_kill(line)
      end
    end
  end
end

#resultsObject



23
24
25
# File 'lib/quake-log-parser/log_reader.rb', line 23

def results
  @line_handler.results
end