Class: LensProtocol::OMA::Type::Base
- Inherits:
-
Object
- Object
- LensProtocol::OMA::Type::Base
- Defined in:
- lib/lens_protocol/oma/type/base.rb
Instance Method Summary collapse
- #format(record, _message) ⇒ Array of lines or a single one
-
#initialize(mode: :single_value) ⇒ Base
constructor
A new instance of Base.
-
#parse(line, message) ⇒ Message
Given a line and a message produces a new message with the record(s) corresponding to that line added to the message.
Constructor Details
#initialize(mode: :single_value) ⇒ Base
Returns a new instance of Base.
5 6 7 |
# File 'lib/lens_protocol/oma/type/base.rb', line 5 def initialize mode: :single_value @mode = mode end |
Instance Method Details
#format(record, _message) ⇒ Array of lines or a single one
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lens_protocol/oma/type/base.rb', line 28 def format record, case @mode when :single_value format_line record.label, [format_value(record.value)] when :array_of_values format_line record.label, format_values(record.value) when :chiral format_line record.label, format_chiral(record.value) when :matrix_of_values record.value.map do |value| format_line record.label, format_values(value) end else raise ArgumentError, "Mode #{@mode} not supported" end end |
#parse(line, message) ⇒ Message
Given a line and a message produces a new message with the record(s) corresponding to that line added to the message
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lens_protocol/oma/type/base.rb', line 11 def parse line, label, data = label_and_data line case @mode when :single_value .add_record label, parse_value(data) when :array_of_values .add_record_or_concat_values label, parse_values(data) when :chiral .add_record label, parse_chiral(data) when :matrix_of_values .add_record_or_insert_values label, parse_values(data) else raise ArgumentError, "Mode #{@mode} not supported" end end |