class Profane::Filter
Attributes
character[RW]
dictionary[RW]
dictionary_regex[RW]
Public Class Methods
new()
click to toggle source
# File lib/profane/filter.rb, line 5 def initialize @dictionary = Profane.dictionary @character = Profane.character end
Public Instance Methods
cleanse!(word)
click to toggle source
# File lib/profane/filter.rb, line 30 def cleanse!(word) value = dictionary[word.match(/\w+/).to_s] return word unless value if value == '' word.gsub!(/\w/, character) else value end end
filter(phrase)
click to toggle source
# File lib/profane/filter.rb, line 10 def filter(phrase) new_phrase = phrase.split(/\s/).map do |word| cleanse!(word) end Array(new_phrase).join(' ') end
profane?(phrase)
click to toggle source
# File lib/profane/filter.rb, line 18 def profane?(phrase) return false unless phrase phrase = phrase.downcase.split(/\s+/) dictionary.keys.each do |key| return true unless phrase.grep(/(\b|\W)#{key.downcase}(\b|\W)/).empty? end false end