š¤¬ Make users' input polite with PoliteText
Olivier Dumas
Posted on November 5, 2020
Hey devs āļø,
At stanza.dev we help developers to share coding concepts and learn from each others. šØāš» š©āš»
We can't monitor each post by hand but as Stanza must be a place full of love š, we have developed a gem that removes the bad words from the website : polite_text
Remove swear words š¤¬
include PoliteText
str = "This gem is a fucking big shit but let's try it"
PoliteText.be_polite!(str)
=> "This gem is a *** big *** but let's try it"
Check if string is polite š āāļø š āāļø
include PoliteText
str = "This gem is a fucking big shit but let's try it"
PoliteText.is_polite?(str)
=> false
Example for an Article model
# == Schema Information
#
# Table name: articles
#
# id :bigint not null, primary key
# text :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Article < ApplicationRecord
include PoliteText
# Callbacks
before_save :make_text_polite
# Methods
def make_text_polite
PoliteText.be_polite!(text)
end
end
Custom swear words list š
You can even pass your custom swear words list that is relevant for your app.
We have opensourced it and we hope that you will like it and contribute to improve it if you want š
š stanza.dev - Learn coding concepts faster
Access the gem repo here
š šŖ š
š©
Olivier Dumas
Posted on November 5, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.