Class: Fbp::Selector_node
Overview
Selector_node
Description
The Selector node class provides for comparing the value(s) in an IP and with set value(s) and the out come of the comparison will determine which output channel the IP will be sent to and thus splitting the incoming stream to different downstream nodes.
The Selector_node class requires an IIP of the form:
Selector => {:comparison => comparison, :value => value, :match => :output_name, :reject => :output_name}
:key
This is the symbol that will be used to match against keys in an IP
:comparison
This is a constant define in constants.rb for comparison operations
:value
This is the value that will be used to check against the corresponding value in an IP
:match
The name of the output queue that will be written to for IPs that match the selector
:reject
The name of the output queue that will be written to for IPs that do not match the selector
There may be multiple selectors with different key values that will match different keys in an IP
When an IP arrives at a Selector_node, the do_node_work will match keys in the IP with keys in the selectors hash. If there is a match, then the comparison stipulated in the selector will be done on the value in the IP against the value in the selector. If the comparison is a match then the IP will be written to the output named in the :match item otherwise it will be written to the output named in the :reject item.
If an IP does not have any keys that match any selectors the IP will be written to the output named :output
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#do_node_work(args) ⇒ Object
Each IP that is presented for processing will be compared to the array of selector records associated with this instance.
-
#initialize(selector = nil) ⇒ Selector_node
constructor
When creating a new Selector_node instance one can provide an array of selector records.
-
#is_ready_to_run? ⇒ Boolean
Checks to see if this Selector_node instance has an array of Selector records.
Methods inherited from Node
#clean_option, #execute, #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(selector = nil) ⇒ Selector_node
When creating a new Selector_node instance one can provide an array of selector records.
47 48 49 50 |
# File 'lib/fbp/selector-node.rb', line 47 def initialize(selector = nil) super() [:selectors] = selector if !selector.nil? end |
Instance Method Details
#do_node_work(args) ⇒ Object
Each IP that is presented for processing will be compared to the array of selector records associated with this instance. The selector records determine how the IP will be output. If there is a match, then the IP will be written to the output channel defined for a match in the selector record. If it does not match the the IP will be written to the output channel defined for a reject in the selector record.
If the incoming IP does not have any of the keys defined in the selector records the IP will be written to the output channel.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/fbp/selector-node.rb', line 73 def do_node_work(args) return false if args.has_key? :completed return true if args.has_key? :start key_match = false selectors = [:selectors] multi_ip = args.has_key? :ips ips = multi_ip ? args[:ips] : [args] ips.each do |ip| selectors.each do |selector_hash| selector_hash.each do |key, h| if ip.has_key? key key_match = true value = ip[key] compare_value = h[:value] comparision = h[:comparison] pass = case comparision when NOT_EQUAL_COMPARE compare_value != value when EQUAL_COMPARE compare_value == value when GREATER_THAN value > compare_value when GREATER_THAN_OR_EQUAL value >= compare_value when LESS_THAN value < compare_value when LESS_THAN_OR_EQUAL value <= compare_value when CONTAINS value.to_s.include?(compare_value.to_s) when DOES_NOT_CONTAINS !value.to_s.include?(compare_value.to_s) when STARTS_WITH value.start_with?(compare_value.to_s) when ENDS_WITH value.end_with?(compare_value.to_s) when MATCHES !value.match(compare_value.to_s).nil? else false end output_name = pass ? h[:match] : h[:reject] write_to_output(ip, output_name) if !output.nil? end end end end write_to_output(args, :output) if !key_match true end |
#is_ready_to_run? ⇒ Boolean
Checks to see if this Selector_node instance has an array of Selector records. If it does have an array of Selector records then true will be returned otherwise false. A Selector_node instance will not execute until it has an array of Selector records
58 59 60 |
# File 'lib/fbp/selector-node.rb', line 58 def is_ready_to_run? .has_key? :selectors end |