Class: TL1::Command
- Inherits:
-
Object
- Object
- TL1::Command
- 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
-
#input_format ⇒ Object
readonly
Returns the value of attribute input_format.
-
#output_format ⇒ Object
readonly
Returns the value of attribute output_format.
Instance Method Summary collapse
-
#initialize(input, output = nil) ⇒ Command
constructor
A new instance of Command.
- #input(**kwargs) ⇒ Object
- #parse_output(output) ⇒ Object
- #record_sources(output) ⇒ Object
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_format ⇒ Object (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_format ⇒ Object (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 |