Class: OneApm::Support::RulesEngine::SegmentTermsRule
- Inherits:
-
Object
- Object
- OneApm::Support::RulesEngine::SegmentTermsRule
- Defined in:
- lib/one_apm/support/rules_engine/segment_terms_rule.rb
Constant Summary collapse
- OA_SEGMENT_PLACEHOLDER =
'*'.freeze
- OA_ADJACENT_PLACEHOLDERS_REGEX =
%r{((?:^|/)\*)(?:/\*)*}.freeze
- OA_ADJACENT_PLACEHOLDERS_REPLACEMENT =
'\1'.freeze
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
Instance Method Summary collapse
- #apply(string) ⇒ Object
- #collapse_adjacent_placeholder_segments(segments) ⇒ Object
-
#initialize(options) ⇒ SegmentTermsRule
constructor
A new instance of SegmentTermsRule.
- #matches?(string) ⇒ Boolean
- #terminal? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ SegmentTermsRule
Returns a new instance of SegmentTermsRule.
13 14 15 16 17 |
# File 'lib/one_apm/support/rules_engine/segment_terms_rule.rb', line 13 def initialize() @prefix = ['prefix'] @terms = ['terms'] @trim_range = (@prefix.size..-1) end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
11 12 13 |
# File 'lib/one_apm/support/rules_engine/segment_terms_rule.rb', line 11 def prefix @prefix end |
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
11 12 13 |
# File 'lib/one_apm/support/rules_engine/segment_terms_rule.rb', line 11 def terms @terms end |
Instance Method Details
#apply(string) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/one_apm/support/rules_engine/segment_terms_rule.rb', line 27 def apply(string) rest = string[@trim_range] leading_slash = rest.slice!(OA_LEADING_SLASH_REGEX) segments = rest.split(OA_SEGMENT_SEPARATOR) segments.map! { |s| @terms.include?(s) ? s : OA_SEGMENT_PLACEHOLDER } transformed_suffix = collapse_adjacent_placeholder_segments(segments) "#{@prefix}#{leading_slash}#{transformed_suffix}" end |
#collapse_adjacent_placeholder_segments(segments) ⇒ Object
38 39 40 41 42 |
# File 'lib/one_apm/support/rules_engine/segment_terms_rule.rb', line 38 def collapse_adjacent_placeholder_segments(segments) joined = segments.join(OA_SEGMENT_SEPARATOR) joined.gsub!(OA_ADJACENT_PLACEHOLDERS_REGEX, OA_ADJACENT_PLACEHOLDERS_REPLACEMENT) joined end |
#matches?(string) ⇒ Boolean
23 24 25 |
# File 'lib/one_apm/support/rules_engine/segment_terms_rule.rb', line 23 def matches?(string) string.start_with?(@prefix) end |
#terminal? ⇒ Boolean
19 20 21 |
# File 'lib/one_apm/support/rules_engine/segment_terms_rule.rb', line 19 def terminal? true end |