class Sauber::Base

Public Class Methods

clean(text) click to toggle source
# File lib/sauber/base.rb, line 4
def clean text 
  return text if text.empty?
  text.split(/(\s)/).collect{ |w| clean_word(w) }.join
end

Private Class Methods

blacklist() click to toggle source
# File lib/sauber/base.rb, line 11
def blacklist
  @blacklist ||= get_content Sauber.blacklist
end
clean_word(word) click to toggle source
# File lib/sauber/base.rb, line 32
def clean_word word
  return word unless word.strip.size > 2

  if word.index(/[\W]/)
    word = word.split(/(\W)/).collect{ |w| clean_word(w) }.join
    subword = word.gsub(/\W/, '')
    word = subword if invalid?(subword)
  end

  invalid?(word) ? replace(word) : word
end
get_content(list) click to toggle source
# File lib/sauber/base.rb, line 44
def get_content list
  case list
  when Array then list
  when String, Pathname then YAML.load_file( list.to_s )
  else []
  end
end
invalid?(word) click to toggle source
# File lib/sauber/base.rb, line 19
def invalid? word
  blacklist.include?(word.downcase) && !whitelist.include?(word.downcase)
end
replace(word) click to toggle source
# File lib/sauber/base.rb, line 23
def replace word       
  case Sauber.replacement
  when :stars
   '*' * word.length
  else
    word
  end
end
whitelist() click to toggle source
# File lib/sauber/base.rb, line 15
def whitelist
  @whitelist ||= get_content Sauber.whitelist
end