šŸ¤¬ Make users' input polite with PoliteText

olivdums

Olivier Dumas

Posted on November 5, 2020

šŸ¤¬ Make users' input polite with PoliteText

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

šŸ’– šŸ’Ŗ šŸ™… šŸš©
olivdums
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.

Related