Skip to content

Commit

Permalink
Alias profane? to banned? (the original)
Browse files Browse the repository at this point in the history
  • Loading branch information
adambair committed Mar 15, 2011
1 parent 44a109b commit 2fe7c1e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
13 changes: 5 additions & 8 deletions lib/profanity_filter.rb
Expand Up @@ -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?
Expand All @@ -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)
Expand All @@ -70,10 +71,6 @@ def replacement(word)
replacement_text
end
end

def is_banned?(word = '')
dictionary.include?(word.downcase)
end
end
end
end
30 changes: 0 additions & 30 deletions test/profanity_filter_test.rb
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.