Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

New language_filter gem #13

@chrisvfritz

Description

@chrisvfritz

Just wanted to give a heads up that I was looking at this and other Ruby profanity filters for work and wasn't finding what I needed, so ended up rolling my own language_filter gem, which works much better for my needs, including:

  • The ability to create multiple, independently configured filter instances
  • Simpler configuration
  • Multiple pre-prackaged matchlists (i.e. blacklists) for language type discrimination (hate, profanity, sex, and violence)
  • More robust exceptionlist (i.e. whitelist) handling
  • And more in the gem's README...

It doesn't include active model integration yet, so instead of profanity_filter :foo, :bar in your Rails model, you'd currently have to have something like:

before_save :clean_up_language

def clean_up_language
  filter = LanguageFilter::Filter.new matchlist: :profanity, replacement: :stars
  foo = filter.sanitize(foo)
  bar = filter.sanitize(bar)
end

So there's still a lot of room for extensibility that I just haven't had time for or had use for yet, but I think it's a more flexible and robust base to work off for most use cases. Hope others find it useful. :-)

(Oh - and development was a bit rushed, so it wasn't test-driven unfortunately. I'll be writing a test suite soon.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions