Browse files

Alias profane? to banned? (the original)

  • Loading branch information...
1 parent 44a109b commit 2fe7c1e5e2769c5dbcbd1cdce94ffff0dbc9ba17 @adambair adambair committed Mar 15, 2011
Showing with 5 additions and 38 deletions.
  1. +5 −8 lib/profanity_filter.rb
  2. +0 −30 test/profanity_filter_test.rb
View
13 lib/profanity_filter.rb
@@ -35,9 +35,10 @@ class Base
@@dictionary = YAML.load_file(@@dictionary_file)
class << self
- def profane?(text, replace_method='')
- text != clean(text, replace_method)
+ def banned?(word = '')
+ dictionary.include?(word.downcase) if word
end
+ alias :profane? :banned?
def clean(text, replace_method = '')
return text if text.blank?
@@ -51,10 +52,10 @@ def clean_word(word)
if word.index(/[\W]/)
word = word.split(/(\W)/).collect{ |subword| clean_word(subword) }.join
concat = word.gsub(/\W/, '')
- word = concat if is_banned? concat
+ word = concat if banned? concat
end
- is_banned?(word) ? replacement(word) : word
+ banned?(word) ? replacement(word) : word
end
def replacement(word)
@@ -70,10 +71,6 @@ def replacement(word)
replacement_text
end
end
-
- def is_banned?(word = '')
- dictionary.include?(word.downcase)
- end
end
end
end
View
30 test/profanity_filter_test.rb
@@ -70,16 +70,6 @@ def test_dictionary_profanity_filter_replaces_punctuation_spaced_profane_words
assert_equal 'f*ck', ProfanityFilter::Base.clean('f.u.c.k', 'dictionary')
assert_equal 'happy-f*ck', ProfanityFilter::Base.clean('happy-fuck', 'dictionary')
end
-
- def test_dictionary_knows_when_text_is_not_profane
- assert !ProfanityFilter::Base.profane?('happy', 'dictionary')
- end
- def test_dictionary_knows_when_text_is_profane
- assert ProfanityFilter::Base.profane?('fuck', 'dictionary')
- end
- def test_dictionary_knows_nil_is_not_profane
- assert !ProfanityFilter::Base.profane?(nil, 'dictionary')
- end
end
@@ -111,16 +101,6 @@ def test_vowels_profanity_filter_replaces_punctuation_spaced_profane_words
assert_equal 'f*ck', ProfanityFilter::Base.clean('f.u.c.k', 'vowels')
assert_equal 'happy-f*ck', ProfanityFilter::Base.clean('happy-fuck', 'vowels')
end
-
- def test_vowels_knows_when_text_is_not_profane
- assert !ProfanityFilter::Base.profane?('happy', 'vowels')
- end
- def test_vowels_knows_when_text_is_profane
- assert ProfanityFilter::Base.profane?('fuck', 'vowels')
- end
- def test_vowels_knows_nil_is_not_profane
- assert !ProfanityFilter::Base.profane?(nil, 'vowels')
- end
end
class HollowProfanityFilterTest < Test::Unit::TestCase
@@ -151,14 +131,4 @@ def test_hollow_profanity_filter_replaces_punctuation_spaced_profane_words
assert_equal 'f**k', ProfanityFilter::Base.clean('f.u.c.k', 'hollow')
assert_equal 'happy-f**k', ProfanityFilter::Base.clean('happy-fuck', 'hollow')
end
-
- def test_hollow_knows_when_text_is_not_profane
- assert !ProfanityFilter::Base.profane?('happy', 'hollow')
- end
- def test_hollow_knows_when_text_is_profane
- assert ProfanityFilter::Base.profane?('fuck', 'hollow')
- end
- def test_hollow_knows_nil_is_not_profane
- assert !ProfanityFilter::Base.profane?(nil, 'hollow')
- end
end

0 comments on commit 2fe7c1e

Please sign in to comment.