Class: ProfanityFilterEngine::RegexpStrategy
- Defined in:
- lib/profanity-filter/engines/regexp_strategy.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_DELIMITER =
'(?:\b|^|$|_)'
Instance Attribute Summary collapse
-
#dictionary ⇒ Object
readonly
Returns the value of attribute dictionary.
-
#profanity_regexp ⇒ Object
readonly
Returns the value of attribute profanity_regexp.
Instance Method Summary collapse
-
#initialize(dictionary:, profanity_regexp: nil) ⇒ RegexpStrategy
constructor
A new instance of RegexpStrategy.
- #profane?(text) ⇒ Boolean
- #profane_words(text) ⇒ Object
Methods inherited from Component
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
#dictionary ⇒ Object (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_regexp ⇒ Object
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
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 |