Class: Cosmos::ProcessorParser
- Defined in:
- lib/cosmos/packets/parsers/processor_parser.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_processor(packet) ⇒ Object
-
#initialize(parser) ⇒ ProcessorParser
constructor
A new instance of ProcessorParser.
- #verify_parameters(cmd_or_tlm) ⇒ Object
Constructor Details
#initialize(parser) ⇒ ProcessorParser
Returns a new instance of ProcessorParser.
34 35 36 |
# File 'lib/cosmos/packets/parsers/processor_parser.rb', line 34 def initialize(parser) @parser = parser end |
Class Method Details
.parse(parser, packet, cmd_or_tlm) ⇒ Object
27 28 29 30 31 |
# File 'lib/cosmos/packets/parsers/processor_parser.rb', line 27 def self.parse(parser, packet, cmd_or_tlm) @parser = ProcessorParser.new(parser) @parser.verify_parameters(cmd_or_tlm) @parser.create_processor(packet) end |
Instance Method Details
#create_processor(packet) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cosmos/packets/parsers/processor_parser.rb', line 49 def create_processor(packet) # require should be performed in target.txt klass = @parser.parameters[1].filename_to_class_name.to_class raise @parser.error("#{@parser.parameters[1].filename_to_class_name} class not found. Did you require the file in target.txt?", @usage) unless klass if @parser.parameters[2] processor = klass.new(*@parser.parameters[2..(@parser.parameters.length - 1)]) else processor = klass.new end raise ArgumentError, "processor must be a Cosmos::Processor but is a #{processor.class}" unless Cosmos::Processor === processor processor.name = get_processor_name() packet.processors[processor.name] = processor rescue Exception => err raise @parser.error(err, @usage) end |
#verify_parameters(cmd_or_tlm) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/cosmos/packets/parsers/processor_parser.rb', line 39 def verify_parameters(cmd_or_tlm) if cmd_or_tlm == PacketConfig::COMMAND raise @parser.error("PROCESSOR only applies to telemetry packets") end @usage = "PROCESSOR <PROCESSOR NAME> <PROCESSOR CLASS FILENAME> <PROCESSOR SPECIFIC OPTIONS>" @parser.verify_num_parameters(2, nil, @usage) end |