class ProfanityFilterEngine::PartialMatchStrategy

Constants

DEFAULT_IGNORE_CASE

Attributes

ignore_case[R]

Public Class Methods

new(dictionary:, ignore_case: DEFAULT_IGNORE_CASE) click to toggle source
# File lib/profanity-filter/engines/partial_match_strategy.rb, line 11
def initialize(dictionary:, ignore_case: DEFAULT_IGNORE_CASE)
  @dictionary = dictionary
  @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/partial_match_strategy.rb, line 19
def build_profanity_regexp
  option = ignore_case ? Regexp::IGNORECASE : nil
  regexp_list = dictionary.map do |word|
    Regexp.new("#{Regexp.escape(word)}", option)
  end

  Regexp.union(*regexp_list)
end