Class: ProfanityFilterEngine::RegexpStrategy

Inherits:
Component
  • Object
show all
Defined in:
lib/profanity-filter/engines/regexp_strategy.rb

Direct Known Subclasses

ExactMatchStrategy, PartialMatchStrategy

Constant Summary collapse

DEFAULT_DELIMITER =
'(?:\b|^|$|_)'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

#profanity_count

Constructor Details

#initialize(dictionary:, profanity_regexp: nil) ⇒ RegexpStrategy

Returns a new instance of RegexpStrategy.



14
15
16
17
# File 'lib/profanity-filter/engines/regexp_strategy.rb', line 14

def initialize(dictionary:, profanity_regexp: nil)
  @dictionary = dictionary
  @profanity_regexp = profanity_regexp || build_profanity_regexp
end

Instance Attribute Details

#dictionaryObject (readonly)

Returns the value of attribute dictionary.



9
10
11
# File 'lib/profanity-filter/engines/regexp_strategy.rb', line 9

def dictionary
  @dictionary
end

#profanity_regexpObject

Returns the value of attribute profanity_regexp.



9
10
11
# File 'lib/profanity-filter/engines/regexp_strategy.rb', line 9

def profanity_regexp
  @profanity_regexp
end

Instance Method Details

#profane?(text) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/profanity-filter/engines/regexp_strategy.rb', line 23

def profane?(text)
  profanity_regexp.match?(text)
end

#profane_words(text) ⇒ Object



19
20
21
# File 'lib/profanity-filter/engines/regexp_strategy.rb', line 19

def profane_words(text)
  text.scan(profanity_regexp).uniq
end