class Mmtrix::Agent::RulesEngine::SegmentTermsRule
Constants
- ADJACENT_PLACEHOLDERS_REGEX
- ADJACENT_PLACEHOLDERS_REPLACEMENT
- SEGMENT_PLACEHOLDER
Attributes
prefix[R]
terms[R]
Public Class Methods
new(options)
click to toggle source
# File lib/mmtrix/agent/rules_engine/segment_terms_rule.rb, line 15 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/mmtrix/agent/rules_engine/segment_terms_rule.rb, line 29 def apply(string) rest = string[@trim_range] leading_slash = rest.slice!(LEADING_SLASH_REGEX) segments = rest.split(SEGMENT_SEPARATOR) segments.map! { |s| @terms.include?(s) ? s : 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/mmtrix/agent/rules_engine/segment_terms_rule.rb, line 40 def collapse_adjacent_placeholder_segments(segments) joined = segments.join(SEGMENT_SEPARATOR) joined.gsub!(ADJACENT_PLACEHOLDERS_REGEX, ADJACENT_PLACEHOLDERS_REPLACEMENT) joined end
matches?(string)
click to toggle source
# File lib/mmtrix/agent/rules_engine/segment_terms_rule.rb, line 25 def matches?(string) string.start_with?(@prefix) end
terminal?()
click to toggle source
# File lib/mmtrix/agent/rules_engine/segment_terms_rule.rb, line 21 def terminal? true end