class Obscenity::Base
Public Class Methods
blacklist()
click to toggle source
# File lib/obscenity/base.rb, line 5 def blacklist @blacklist ||= set_list_content(Obscenity.config.blacklist) end
blacklist=(value)
click to toggle source
# File lib/obscenity/base.rb, line 9 def blacklist=(value) @blacklist = value == :default ? set_list_content(Obscenity::Config.new.blacklist) : value end
offensive(text)
click to toggle source
# File lib/obscenity/base.rb, line 40 def offensive(text) words = [] blacklist.each do |foul| words << foul if text =~ /\b#{foul}\b/i && !whitelist.include?(foul) end words.uniq end
profane?(text)
click to toggle source
# File lib/obscenity/base.rb, line 21 def profane?(text) blacklist.any? do |foul| text =~ /\b#{foul}\b/i && !whitelist.include?(foul) end end
replace(word)
click to toggle source
# File lib/obscenity/base.rb, line 48 def replace(word) content = @scoped_replacement || Obscenity.config.replacement case content when :vowels then word.gsub(/[aeiou]/i, '*') when :stars then '*' * word.size when :nonconsonants then word.gsub(/[^bcdfghjklmnpqrstvwxyz]/i, '*') when :default, :garbled then '$@!#%' else content end end
replacement(chars)
click to toggle source
# File lib/obscenity/base.rb, line 35 def replacement(chars) @scoped_replacement = chars self end
sanitize(text)
click to toggle source
# File lib/obscenity/base.rb, line 27 def sanitize(text) blacklist.each do |foul| text.gsub!(/\b#{foul}\b/i, replace(foul)) unless whitelist.include?(foul) end @scoped_replacement = nil text end
whitelist()
click to toggle source
# File lib/obscenity/base.rb, line 13 def whitelist @whitelist ||= set_list_content(Obscenity.config.whitelist) end
whitelist=(value)
click to toggle source
# File lib/obscenity/base.rb, line 17 def whitelist=(value) @whitelist = value == :default ? set_list_content(Obscenity::Config.new.whitelist) : value end
Private Class Methods
set_list_content(list)
click to toggle source
# File lib/obscenity/base.rb, line 61 def set_list_content(list) case list when Array then list when String, Pathname then ::YAML.load_file( list.to_s ) else [] end end