class WordSubstitution
Attributes
good_words[R]
Public Class Methods
new(params)
click to toggle source
# File lib/snarkify/word_substitution.rb, line 4 def initialize(params) @good_words = params.fetch("good") @bad_words = params.fetch("bad") end
Public Instance Methods
snarkify!(content)
click to toggle source
# File lib/snarkify/word_substitution.rb, line 9 def snarkify!(content) @good_words.each do |word| content.gsub!(/([^a-zA-Z])#{word}([^a-zA-Z])/im, "\\1#{get_bad_word}\\2") end content end
Private Instance Methods
get_bad_word()
click to toggle source
# File lib/snarkify/word_substitution.rb, line 18 def get_bad_word @bad_words.sample end