class ProfanityFilterEngine::ExactMatchStrategy

Constants

DEFAULT_IGNORE_CASE
DELIMITER

Attributes

delimiter[R]
ignore_case[R]

Public Class Methods

new(dictionary:, ignore_case: DEFAULT_IGNORE_CASE) click to toggle source
# File lib/profanity-filter/engines/exact_match_strategy.rb, line 13
def initialize(dictionary:, ignore_case: DEFAULT_IGNORE_CASE)
  @dictionary = dictionary
  @delimiter = DELIMITER
  @ignore_case = ignore_case
  @profanity_regexp = build_profanity_regexp
end

Private Instance Methods

build_profanity_regexp() click to toggle source
# File lib/profanity-filter/engines/exact_match_strategy.rb, line 22
def build_profanity_regexp
  option = ignore_case ? Regexp::IGNORECASE : nil
  regexp_list = dictionary.map do |word|
    Regexp.new("#{delimiter}#{build_word_regexp(word)}#{delimiter}", option)
  end

  Regexp.union(*regexp_list)
end
build_word_regexp(word) click to toggle source
# File lib/profanity-filter/engines/exact_match_strategy.rb, line 31
def build_word_regexp(word)
  Regexp.escape(word)
end