Class: TF2LineParser::Line

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ Line

Returns a new instance of Line.



11
12
13
# File 'lib/tf2_line_parser/line.rb', line 11

def initialize(line)
  @line = line
end

Instance Attribute Details

#lineObject

Returns the value of attribute line.



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

def line
  @line
end

Instance Method Details

#parseObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tf2_line_parser/line.rb', line 15

def parse
  Events::Event.types.each do |type|
    begin
      match = line.match(type.regex)
    rescue ArgumentError
      tidied_line = ActiveSupport::Multibyte::Chars.new(line).tidy_bytes
      match = tidied_line.match(type.regex)
    end
    if match
      @match ||= type.new(*type.regex_results(match))
      break
    end
  end
  @match
end