Class: ProfanityFilterEngine::Composite

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

#profanity_count

Constructor Details

#initializeComposite

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

#strategiesObject (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

Returns:

  • (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