Class: NewRelic::Agent::RulesEngine::Rule
- Inherits:
-
Object
- Object
- NewRelic::Agent::RulesEngine::Rule
- Defined in:
- lib/new_relic/agent/rules_engine.rb
Instance Attribute Summary collapse
-
#each_segment ⇒ Object
readonly
Returns the value of attribute each_segment.
-
#eval_order ⇒ Object
readonly
Returns the value of attribute eval_order.
-
#ignore ⇒ Object
readonly
Returns the value of attribute ignore.
-
#match_expression ⇒ Object
readonly
Returns the value of attribute match_expression.
-
#replace_all ⇒ Object
readonly
Returns the value of attribute replace_all.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
-
#terminate_chain ⇒ Object
readonly
Returns the value of attribute terminate_chain.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #apply(string) ⇒ Object
-
#initialize(options) ⇒ Rule
constructor
A new instance of Rule.
- #map_to_list(list) ⇒ Object
Constructor Details
#initialize(options) ⇒ Rule
Returns a new instance of Rule.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/new_relic/agent/rules_engine.rb', line 33 def initialize() if !['match_expression'] raise ArgumentError.new('missing required match_expression') end if !['replacement'] && !['ignore'] raise ArgumentError.new('must specify replacement when ignore is false') end @match_expression = Regexp.new(['match_expression']) @replacement = ['replacement'] @ignore = ['ignore'] || false @eval_order = ['eval_order'] || 0 @replace_all = ['replace_all'] || false @each_segment = ['each_segment'] || false @terminate_chain = ['terminate_chain'] || false end |
Instance Attribute Details
#each_segment ⇒ Object (readonly)
Returns the value of attribute each_segment.
30 31 32 |
# File 'lib/new_relic/agent/rules_engine.rb', line 30 def each_segment @each_segment end |
#eval_order ⇒ Object (readonly)
Returns the value of attribute eval_order.
30 31 32 |
# File 'lib/new_relic/agent/rules_engine.rb', line 30 def eval_order @eval_order end |
#ignore ⇒ Object (readonly)
Returns the value of attribute ignore.
30 31 32 |
# File 'lib/new_relic/agent/rules_engine.rb', line 30 def ignore @ignore end |
#match_expression ⇒ Object (readonly)
Returns the value of attribute match_expression.
30 31 32 |
# File 'lib/new_relic/agent/rules_engine.rb', line 30 def match_expression @match_expression end |
#replace_all ⇒ Object (readonly)
Returns the value of attribute replace_all.
30 31 32 |
# File 'lib/new_relic/agent/rules_engine.rb', line 30 def replace_all @replace_all end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
30 31 32 |
# File 'lib/new_relic/agent/rules_engine.rb', line 30 def replacement @replacement end |
#terminate_chain ⇒ Object (readonly)
Returns the value of attribute terminate_chain.
30 31 32 |
# File 'lib/new_relic/agent/rules_engine.rb', line 30 def terminate_chain @terminate_chain end |
Instance Method Details
#<=>(other) ⇒ Object
66 67 68 |
# File 'lib/new_relic/agent/rules_engine.rb', line 66 def <=>(other) eval_order <=> other.eval_order end |
#apply(string) ⇒ Object
50 51 52 53 54 |
# File 'lib/new_relic/agent/rules_engine.rb', line 50 def apply(string) method = @replace_all ? :gsub : :sub result = string.send(method, @match_expression, @replacement) [result, result != string] end |
#map_to_list(list) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/new_relic/agent/rules_engine.rb', line 56 def map_to_list(list) matched = false result = list.map do |string| str_result, str_match = apply(string) matched ||= str_match str_result end [result, matched] end |