Class: Fbp::Counter_node
Overview
Description
The counter node counts either incoming IPs or IPs that contain a certain key and then adds that count data to the incoming IPs
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#do_node_work(args) ⇒ Object
When an IP is received if a key has been set then the IP will be checked to see if it contains that key.
-
#initialize(key = nil) ⇒ Counter_node
constructor
When creating a new Counter_node instance one can optionally provide a symbol which would be used to match a key in an incoming IP.
Methods inherited from Node
#clean_option, #execute, #is_ready_to_run?, #merge_options!, #register_for_output_from_node, #set_option, #stop, #unregister_for_output_from_node, #wait_until_completed, #write_to_input, #write_to_output
Constructor Details
#initialize(key = nil) ⇒ Counter_node
When creating a new Counter_node instance one can optionally provide a symbol which would be used to match a key in an incoming IP. The IP would then only be counted if the IP contained that key.
15 16 17 18 |
# File 'lib/fbp/counter-node.rb', line 15 def initialize(key = nil) super() [:key] = key if !key.nil? end |
Instance Method Details
#do_node_work(args) ⇒ Object
When an IP is received if a key has been set then the IP will be checked to see if it contains that key. If so then it is counted.
If the incoming IP has the :ips key then the nested IPs will be search for the matching key and counted if found.
In either a single IP or an IP with the :ips key is received and no key has been set, then all IPs will be counted.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fbp/counter-node.rb', line 30 def do_node_work(args) counter = 0 ips = args.has_key? :ips ? args[:ips] : [args] key = nil key = [:key] if .has_key?(:key) ips.each do |ip| if key.nil? counter += 1 else counter += 1 if ip.has_key?(key) end end args[:counter] = counter super(args) end |