lib/bad_word_detector.rb
#
# Searches string for some word in library
# 
# @param text [String] String to search
# 
# @param return_white [Boolean] Flag to indicate if search should return whitelist word
# 
# @return [BadWord, nil] BadWord object, containing information about found word and it's position in text
# 
Searches string for some word in library
Searches string for some word in library
def find(text, return_white = false)
    downcased = text.downcase
    length = text.length
    index = 0
    while index < length
      found = find_part(downcased, index)
      if found 
        word = BadWord.new(
          found[:word], 
          text, 
          index, 
          found[:length], 
          @whitelist)
        if not word.white? or return_white
          return word
        end
      end
      index += 1
    end
  end
def find ( text , return_white = false ) downcased = text . downcase length = text . length index = 0 while index < length found = find_part ( downcased , index ) if found word = BadWord . new ( found [ :word ] , text , index , found [ :length ] , @whitelist ) if not word . white? or return_white return word end end index += 1 end end
Searches string for some word in library
Searches string for some word in library
BadWord object, containing information about found word and it's position in text
BadWord object containing information about found word and it ' s position in text
BadWord, nil
text
String to search
String to search
return_white
Flag to indicate if search should return whitelist word
Flag to indicate if search should return whitelist word