Class: OpenC3::Conversion
- Defined in:
- lib/openc3/conversions/conversion.rb
Overview
Performs a general conversion via the implementation of the call method
Direct Known Subclasses
BitReverseConversion, GenericConversion, IpReadConversion, IpWriteConversion, ObjectReadConversion, PacketTimeFormattedConversion, PacketTimeSecondsConversion, ProcessorConversion, ReceivedCountConversion, ReceivedTimeFormattedConversion, ReceivedTimeSecondsConversion, SegmentedPolynomialConversion, UnixTimeConversion
Instance Attribute Summary collapse
-
#converted_array_size ⇒ Integer
readonly
The size in bits of the converted array value.
-
#converted_bit_size ⇒ Integer
readonly
The size in bits of the converted value.
-
#converted_type ⇒ Symbol
readonly
The converted data type.
-
#params ⇒ Array
readonly
The arguments passed to the conversion.
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
-
#call(_value, _packet, _buffer) ⇒ Object
Perform the conversion on the value.
-
#initialize ⇒ Conversion
constructor
Create a new conversion.
-
#to_config(read_or_write) ⇒ String
Config fragment for this conversion.
-
#to_s ⇒ String
The conversion class.
Constructor Details
#initialize ⇒ Conversion
Create a new conversion
37 38 39 40 41 42 |
# File 'lib/openc3/conversions/conversion.rb', line 37 def initialize @converted_type = nil @converted_bit_size = nil @converted_array_size = nil @params = nil end |
Instance Attribute Details
#converted_array_size ⇒ Integer (readonly)
Returns The size in bits of the converted array value.
32 33 34 |
# File 'lib/openc3/conversions/conversion.rb', line 32 def converted_array_size @converted_array_size end |
#converted_bit_size ⇒ Integer (readonly)
Returns The size in bits of the converted value.
30 31 32 |
# File 'lib/openc3/conversions/conversion.rb', line 30 def converted_bit_size @converted_bit_size end |
#converted_type ⇒ Symbol (readonly)
Returns The converted data type. Must be one of StructureItem#data_type.
28 29 30 |
# File 'lib/openc3/conversions/conversion.rb', line 28 def converted_type @converted_type end |
#params ⇒ Array (readonly)
Returns The arguments passed to the conversion.
34 35 36 |
# File 'lib/openc3/conversions/conversion.rb', line 34 def params @params end |
Instance Method Details
#as_json(*a) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/openc3/conversions/conversion.rb', line 67 def as_json(*a) result = {} result['class'] = self.class.name.to_s result['converted_type'] = @converted_type if @converted_type result['converted_bit_size'] = @converted_bit_size if @converted_bit_size result['converted_array_size'] = @converted_array_size if @converted_array_size result['params'] = @params.as_json(*a) if @params result end |
#call(_value, _packet, _buffer) ⇒ Object
Perform the conversion on the value.
52 53 54 |
# File 'lib/openc3/conversions/conversion.rb', line 52 def call(_value, _packet, _buffer) raise "call method must be defined by subclass" end |
#to_config(read_or_write) ⇒ String
Returns Config fragment for this conversion.
63 64 65 |
# File 'lib/openc3/conversions/conversion.rb', line 63 def to_config(read_or_write) " #{read_or_write}_CONVERSION #{self.class.name.class_name_to_filename}\n" end |
#to_s ⇒ String
Returns The conversion class.
57 58 59 |
# File 'lib/openc3/conversions/conversion.rb', line 57 def to_s self.class.to_s.split('::')[-1] end |