Class: PoliteText::TextCleaner

Inherits:
Base
  • Object
show all
Defined in:
lib/polite_text/text_cleaner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#swear_words, #swear_words_list

Constructor Details

#initialize(text) ⇒ TextCleaner

Returns a new instance of TextCleaner.

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/polite_text/text_cleaner.rb', line 5

def initialize(text)
  raise ArgumentError.new('The text can not be nil') if text.nil?

  @text = text.to_s
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/polite_text/text_cleaner.rb', line 3

def text
  @text
end

Instance Method Details

#clean!Object



11
12
13
# File 'lib/polite_text/text_cleaner.rb', line 11

def clean!
  text.gsub!(swear_words, '***') || text
end