diff --git a/README.md b/README.md index c0ce04a..63ef65d 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ The following methods are available to use with Obscenity: - :stars : Replaces profane words with '*' up to the word's length - :vowels : Replaces the vowels in the profane word with '*' - :nonconsonants : Replaces non consonants with '*' +- :hollow : Replaces all but the first and last letter with '*' - "custom string" : Replaces the profane word with the custom string Example: @@ -87,7 +88,7 @@ Obscenity.sanitize("text with shit") => "text with $@!#%" ``` -`Obscenity.replacement(style).sanitize(text)` allows you to pass the replacement method to be used when sanitizing the given content. Available replacement values are `:default`, `:garbled`, `:stars`, `:vowels`, and a custom string. +`Obscenity.replacement(style).sanitize(text)` allows you to pass the replacement method to be used when sanitizing the given content. Available replacement values are `:default`, `:garbled`, `:stars`, `:vowels`, `:hollow`, and a custom string. ```ruby Obscenity.replacement(:default).sanitize("text with shit") @@ -105,6 +106,9 @@ Obscenity.replacement(:vowels).sanitize("text with shit") Obscenity.replacement(:nonconsonants).sanitize('Oh 5hit') => "Oh *h*t" +Obscenity.replacement(:hollow).sanitize('Oh 5hit') +=> "Oh 5**t" + Obscenity.replacement("[censored]").sanitize("text with shit") => "text with [censored]" ``` diff --git a/lib/obscenity/base.rb b/lib/obscenity/base.rb index 44063c7..5b42112 100644 --- a/lib/obscenity/base.rb +++ b/lib/obscenity/base.rb @@ -52,6 +52,7 @@ def offensive(text) def replace(word) content = @scoped_replacement || Obscenity.config.replacement case content + when :hollow then (word.size > 2) ? word[0,1] + ('*' * (word.size-2)) + word[-1,1] : word when :vowels then word.gsub(/[aeiou]/i, '*') when :stars then '*' * word.size when :nonconsonants then word.gsub(/[^bcdfghjklmnpqrstvwxyz]/i, '*') diff --git a/test/test_base.rb b/test/test_base.rb index 37be492..58b3330 100644 --- a/test/test_base.rb +++ b/test/test_base.rb @@ -242,6 +242,7 @@ class TestBase < Test::Unit::TestCase context "#replace" do should "replace the given word by the given replacement method" do [ + [:hollow, {original: "Oh 5hit", clean: "Oh 5**t"}], [:vowels, {original: "Oh 5hit", clean: "Oh 5h*t"}], [:nonconsonants, {original: "Oh 5hit", clean: "Oh *h*t"}], [:stars, {original: "Oh 5hit", clean: "Oh ****"}],