Class: Cosmos::WatermarkProcessor

Inherits:
Processor show all
Defined in:
lib/cosmos/processors/watermark_processor.rb

Instance Attribute Summary

Attributes inherited from Processor

#name, #results, #value_type

Instance Method Summary collapse

Methods inherited from Processor

#clone, #to_s

Constructor Details

#initialize(item_name, value_type = :CONVERTED) ⇒ WatermarkProcessor

Returns a new instance of WatermarkProcessor.

Parameters:

  • item_name (String)

    The name of the item to gather statistics on

  • value_type (defaults to: :CONVERTED)

    #See Processor::initialize



26
27
28
29
30
# File 'lib/cosmos/processors/watermark_processor.rb', line 26

def initialize(item_name, value_type = :CONVERTED)
  super(value_type)
  @item_name = item_name.to_s.upcase
  reset()
end

Instance Method Details

#as_jsonObject



54
55
56
# File 'lib/cosmos/processors/watermark_processor.rb', line 54

def as_json
  { 'name' => @name, 'class' => self.class.name, 'params' => [@item_name, @value_type.to_s] }
end

#call(packet, buffer) ⇒ Object

Run watermarks on the item

See Processor#call



35
36
37
38
39
40
41
# File 'lib/cosmos/processors/watermark_processor.rb', line 35

def call(packet, buffer)
  value = packet.read(@item_name, @value_type, buffer)
  high_water = @results[:HIGH_WATER]
  @results[:HIGH_WATER] = value if !high_water or value > high_water
  low_water = @results[:LOW_WATER]
  @results[:LOW_WATER] = value if !low_water or value < low_water
end

#resetObject

Reset any state



44
45
46
47
# File 'lib/cosmos/processors/watermark_processor.rb', line 44

def reset
  @results[:HIGH_WATER] = nil
  @results[:LOW_WATER] = nil
end

#to_configObject

Convert to configuration file string



50
51
52
# File 'lib/cosmos/processors/watermark_processor.rb', line 50

def to_config
  "  PROCESSOR #{@name} #{self.class.name.to_s.class_name_to_filename} #{@item_name} #{@value_type}\n"
end