Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Detects and masks banned words within a text
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.travis.yml
Gemfile
LICENSE
README.md
Rakefile
banned_words.gemspec

README.md

Banned Words

Detects and masks banned words within a text

Build Status

Installation

Add this line in your Gemfile:

gem 'banned_words'

Then you need to run:

rails g banned_words

to generate the banned_words.yml file.

Usage

Masking

# Single banned word
BannedWords.create!('dog')
phrase = 'Red d-o-g'
BannedWords.mask(phrase)
> 'Red *Buzz*'

# With an array of banned words
BannedWords.create!(['fox', 'over'])
phrase = 'The quick brown fox jumps over the lazy dog'
BannedWords.mask(phrase)
> 'The quick brown *Buzz* jumps *Buzz* the lazy *Buzz*'

# Override the masking word
BannedWords.mask(phrase, "*Bad Word*")
> 'The quick brown *Bad Word* jumps *Bad Word* the lazy *Bad Word*'

Detecting

BannedWords.create!(['quick', 'jumps'])
phrase = 'The q-u#-_^i!c~k brown fox j=u m p?s over the lazy dog'
BannedWords.detect(phrase)
> ['q-u#-_^i!c~k', 'j=u m p?s']

Listing

BannedWords.list
> ['dog', 'fox', 'over']

Removing

BannedWords.remove('dog')
BannedWords.list
> ['fox', 'over']

# Another example:
BannedWords.remove(['fox', 'over'])
BannedWords.list
> []

Copyright

See LICENSE for details.

Something went wrong with that request. Please try again.