Class: Filter::Phrase

Inherits:
Filter
  • Object
show all
Defined in:
lib/filters/phrase.rb

Direct Known Subclasses

Profanity

Constant Summary

Constants inherited from Filter

VERSION

Instance Attribute Summary collapse

Attributes inherited from Filter

#string

Instance Method Summary collapse

Methods inherited from Filter

Profanity, Profanity!, #filter, inherited

Constructor Details

#initialize(string, options = {}) ⇒ Phrase

Initialize with string and options.



18
19
20
21
22
# File 'lib/filters/phrase.rb', line 18

def initialize string, options = {}
  super
  @phrases = options.fetch :phrases, []
  @mask = options.fetch :mask, nil
end

Instance Attribute Details

#maskObject (readonly)

Mask string.



13
14
15
# File 'lib/filters/phrase.rb', line 13

def mask
  @mask
end

#phrasesObject (readonly)

Array of phrases.



8
9
10
# File 'lib/filters/phrase.rb', line 8

def phrases
  @phrases
end

Instance Method Details

#filter!Object

Filter phrases.



27
28
29
30
31
32
33
34
35
36
# File 'lib/filters/phrase.rb', line 27

def filter!
  phrases.each do |phrase|
    if phrase.is_a? Array
      filter_with phrase.shift, phrase.shift
    else
      filter_with phrase, mask
    end
  end
  string.strip
end