Class: ProfanityFilterEngine::Composite
- Defined in:
- lib/profanity-filter/engines/composite.rb
Instance Attribute Summary collapse
-
#strategies ⇒ Object
readonly
Returns the value of attribute strategies.
Instance Method Summary collapse
- #add_strategies(*new_strategies) ⇒ Object
- #add_strategy(strategy) ⇒ Object
- #delete_strategy(strategy) ⇒ Object
-
#initialize ⇒ Composite
constructor
A new instance of Composite.
- #profane?(text) ⇒ Boolean
- #profane_words(text) ⇒ Object
Methods inherited from Component
Constructor Details
#initialize ⇒ Composite
Returns a new instance of Composite.
10 11 12 |
# File 'lib/profanity-filter/engines/composite.rb', line 10 def initialize @strategies = [] end |
Instance Attribute Details
#strategies ⇒ Object (readonly)
Returns the value of attribute strategies.
8 9 10 |
# File 'lib/profanity-filter/engines/composite.rb', line 8 def strategies @strategies end |
Instance Method Details
#add_strategies(*new_strategies) ⇒ Object
18 19 20 |
# File 'lib/profanity-filter/engines/composite.rb', line 18 def add_strategies(*new_strategies) strategies.concat(new_strategies) end |
#add_strategy(strategy) ⇒ Object
14 15 16 |
# File 'lib/profanity-filter/engines/composite.rb', line 14 def add_strategy(strategy) strategies << strategy end |
#delete_strategy(strategy) ⇒ Object
22 23 24 |
# File 'lib/profanity-filter/engines/composite.rb', line 22 def delete_strategy(strategy) strategies.delete(strategy) end |
#profane?(text) ⇒ Boolean
26 27 28 |
# File 'lib/profanity-filter/engines/composite.rb', line 26 def profane?(text) strategies.any? { |strategy| strategy.profane?(text) } end |
#profane_words(text) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/profanity-filter/engines/composite.rb', line 30 def profane_words(text) total_words = strategies.reduce([]) do |words, strategy| words.concat(strategy.profane_words(text).map { |w| w.gsub(/[ _\-\.]/, '') }) end total_words.uniq end |