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.
26 27 28 |
# File 'lib/cosmos/packets/parsers/processor_parser.rb', line 26 def initialize(parser) @parser = parser end |
Class Method Details
.parse(parser, packet, cmd_or_tlm) ⇒ Object
19 20 21 22 23 |
# File 'lib/cosmos/packets/parsers/processor_parser.rb', line 19 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cosmos/packets/parsers/processor_parser.rb', line 40 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
31 32 33 34 35 36 37 |
# File 'lib/cosmos/packets/parsers/processor_parser.rb', line 31 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 |