Class: TacviewClient::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/tacview_client/reader.rb,
lib/tacview_client/reader/parser.rb

Overview

Reads events from an input source, parses them using the Parser and calls the appropriate event processor method

Defined Under Namespace

Classes: Parser

Constant Summary collapse

OBJECT_UPDATE_MARKER =

The format that matches the beginning of an ACMI update line

'^\h\h+,'
OBJECT_DELETION_MARKER =

The format that matches the beginning of an ACMI delete line

'-'
TIME_UPDATE_MARKER =

The format that matches the beginning of an ACMI time update line

'#'
GLOBAL_PROPERTY_MARKER =

The format that matches the beginning of an ACMI Property line

'0,'

Instance Method Summary collapse

Constructor Details

#initialize(input_source:, processor:) ⇒ Reader

Returns a new instance of Reader.

Parameters:

  • input_source (IO, #gets)

    An IO object (or object that implements the IO#gets method. Typically this is a Socket or File.

  • processor (BaseProcessor)

    The object that processes the events emitted by the TacviewClient::Reader. Must implement the methods defined by the BaseProcessor and can optionally inherit from it.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
# File 'lib/tacview_client/reader.rb', line 27

def initialize(input_source:, processor:)
  raise ArgumentError, 'input_source cannot be nil' if input_source.nil?
  raise ArgumentError, 'processor cannot be nil' if processor.nil?

  @input_source = input_source
  @processor = processor
end

Instance Method Details

#start_readingObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/tacview_client/reader.rb', line 35

def start_reading
  while (line = @input_source.gets)
    route_line(line.chomp)
  end
  true
rescue SignalException
  exit
ensure
  @input_source.close
end