Skip to content
This repository was archived by the owner on Dec 19, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand All @@ -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]"
```
Expand Down
1 change: 1 addition & 0 deletions lib/obscenity/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, '*')
Expand Down
1 change: 1 addition & 0 deletions test/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ****"}],
Expand Down