Class: TL1::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/tl1/command.rb

Overview

A representation of a CLI interaction, including an input message format and an output message format.

Defined Under Namespace

Classes: OutputScanner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, output = nil) ⇒ Command

Returns a new instance of Command.



10
11
12
13
# File 'lib/tl1/command.rb', line 10

def initialize(input, output = nil)
  @input_format = TL1::InputFormat.new(input)
  @output_format = output && TL1::OutputFormat.new(output)
end

Instance Attribute Details

#input_formatObject (readonly)

Returns the value of attribute input_format.



8
9
10
# File 'lib/tl1/command.rb', line 8

def input_format
  @input_format
end

#output_formatObject (readonly)

Returns the value of attribute output_format.



8
9
10
# File 'lib/tl1/command.rb', line 8

def output_format
  @output_format
end

Instance Method Details

#input(**kwargs) ⇒ Object



15
16
17
# File 'lib/tl1/command.rb', line 15

def input(**kwargs)
  input_format.format(**kwargs) + ';'
end

#parse_output(output) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/tl1/command.rb', line 23

def parse_output(output)
  return output unless output_format

  record_sources(output).map do |record_source|
    output_format.parse(record_source)
  end
end

#record_sources(output) ⇒ Object



19
20
21
# File 'lib/tl1/command.rb', line 19

def record_sources(output)
  OutputScanner.new(output).records
end