Module: Cleaner

Extended by:
Cleaner
Included in:
Cleaner
Defined in:
lib/cleanerupper.rb

Overview

Author.….…: Mike Trpcic

Last Updated..: March 28, 2010

Description:  Cleans all inappropriate data from the database

(c) Fluid Media Inc.

Defined Under Namespace

Modules: ActiveRecord, Extension Classes: Data

Class Method Summary collapse

Class Method Details

.custom_clean(value, dict, match, func) ⇒ Object

This is a wrapper method for custom cleaning methods defined by a user



85
86
87
88
89
90
91
# File 'lib/cleanerupper.rb', line 85

def self.custom_clean(value, dict, match, func)
  dict.each do |word|
    rxp = match ? /#{word}/ : /#{word}/i
    value.to_s.gsub!(rxp, func.call(word))
  end
  value
end

.remove(value, dict, match) ⇒ Object

This method removes selected words from the string and replaces them with nothing



104
105
106
107
108
109
110
# File 'lib/cleanerupper.rb', line 104

def self.remove(value, dict, match)
  dict.each do |word|
    rxp = match ? /#{word}/ : /#{word}/i
    value.to_s.gsub!(rxp, "")
  end
  value
end

.replace(value, dict, match) ⇒ Object

This method removes selected words from the string and replaces them with ‘swear’ characters,such as ‘#$@!%&’



114
115
116
117
118
119
120
# File 'lib/cleanerupper.rb', line 114

def self.replace(value, dict, match)
  dict.each do |word|
    rxp = match ? /#{word}/ : /#{word}/i
    value.to_s.gsub!(rxp, word.split(//).map{|char| char = Cleaner::Data.replacement_chars.shuffle[0]}.join(''))
  end
  value
end

.scramble(value, dict, match) ⇒ Object

This method scrambles data by rearranging the letters.



94
95
96
97
98
99
100
# File 'lib/cleanerupper.rb', line 94

def self.scramble(value, dict, match) 
  dict.each do |word|
    rxp = match ? /#{word}/ : /#{word}/i
    value.to_s.gsub!(rxp, word.split(//).shuffle.join(''))
  end
  value
end