class OneApm::Support::RulesEngine::SegmentTermsRule
Constants
- OA_ADJACENT_PLACEHOLDERS_REGEX
- OA_ADJACENT_PLACEHOLDERS_REPLACEMENT
- OA_SEGMENT_PLACEHOLDER
Attributes
prefix[R]
terms[R]
Public Class Methods
new(options)
click to toggle source
# File lib/one_apm/support/rules_engine/segment_terms_rule.rb, line 13 def initialize(options) @prefix = options['prefix'] @terms = options['terms'] @trim_range = (@prefix.size..-1) end
Public Instance Methods
apply(string)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/one_apm/support/rules_engine/segment_terms_rule.rb, line 23 def matches?(string) string.start_with?(@prefix) end
terminal?()
click to toggle source
# File lib/one_apm/support/rules_engine/segment_terms_rule.rb, line 19 def terminal? true end