Class: Cosmos::Processor
Direct Known Subclasses
NewPacketLogProcessor, StatisticsProcessor, WatermarkProcessor
Instance Attribute Summary collapse
-
#name ⇒ String
The processor name.
-
#results ⇒ Hash
The results of the most recent execution of the processor.
-
#value_type ⇒ Symbol
readonly
The value type for the processor.
Instance Method Summary collapse
-
#call(packet, buffer) ⇒ Object
Perform processing on the packet.
-
#clone ⇒ Processor
(also: #dup)
Make a light weight clone of this processor.
-
#initialize(value_type = :CONVERTED) ⇒ Processor
constructor
Create a new Processor.
-
#reset ⇒ Object
Reset any state.
-
#to_s ⇒ String
The processor class.
Constructor Details
#initialize(value_type = :CONVERTED) ⇒ Processor
Create a new Processor
26 27 28 29 30 31 32 |
# File 'lib/cosmos/processors/processor.rb', line 26 def initialize(value_type = :CONVERTED) @name = self.class.to_s.upcase value_type = value_type.to_s.upcase.intern @value_type = value_type raise ArgumentError, "value_type must be RAW, CONVERTED, FORMATTED, or WITH_UNITS. Is #{@value_type}" unless Packet::VALUE_TYPES.include?(@value_type) @results = {} end |
Instance Attribute Details
#name ⇒ String
Returns The processor name.
19 20 21 |
# File 'lib/cosmos/processors/processor.rb', line 19 def name @name end |
#results ⇒ Hash
Returns The results of the most recent execution of the processor.
22 23 24 |
# File 'lib/cosmos/processors/processor.rb', line 22 def results @results end |
#value_type ⇒ Symbol (readonly)
Returns The value type for the processor.
16 17 18 |
# File 'lib/cosmos/processors/processor.rb', line 16 def value_type @value_type end |
Instance Method Details
#call(packet, buffer) ⇒ Object
Perform processing on the packet.
45 46 47 |
# File 'lib/cosmos/processors/processor.rb', line 45 def call(packet, buffer) raise "call method must be defined by subclass" end |
#clone ⇒ Processor Also known as: dup
Make a light weight clone of this processor. This only creates a new hash of results
62 63 64 65 66 |
# File 'lib/cosmos/processors/processor.rb', line 62 def clone processor = super() processor.results = processor.results.clone processor end |
#reset ⇒ Object
Reset any state
55 56 57 |
# File 'lib/cosmos/processors/processor.rb', line 55 def reset # By default do nothing end |
#to_s ⇒ String
Returns The processor class.
50 51 52 |
# File 'lib/cosmos/processors/processor.rb', line 50 def to_s self.class.to_s.split('::')[-1] end |