Module: BadWords

Defined in:
lib/version.rb,
lib/bad_words.rb

Defined Under Namespace

Modules: Version

Class Method Summary collapse

Class Method Details

.clean_string(str, bad_words) ⇒ Object



23
24
25
26
27
# File 'lib/bad_words.rb', line 23

def self.clean_string(str, bad_words)
  str_broken = str.downcase.split(' ')
  bad_words.any? { |bw| str_broken.include?(bw) }
  (str_broken - bad_words).join(' ') 
end

.load_words(nivel) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bad_words.rb', line 34

def self.load_words(nivel)
  @words = YAML.load_file File.join(File.dirname(__FILE__), "../config/words.yml")
   words_define = ""
    if nivel == 1 || nivel == 3
      words_define << @words['bad_words'] << " "
    end
    if nivel == 2 || nivel == 3
      words_define << @words['block_words']
    end
    words_define
end

.make_clean(str, nivel) ⇒ Object

Str : String Nivel 1 : clean bad words. Nivel 2 : clean block words name of concurrence, name of group or products of group Nivel 3 : use all filters



9
10
11
12
# File 'lib/bad_words.rb', line 9

def self.make_clean(str, nivel)
  words_define = load_words(nivel)
  clean_string(str, words_define.split(' '))
end

.make_verify(str, nivel) ⇒ Object

Str : String Nivel 1 : verify bad words. Nivel 2 : verify block words name of concurrence, name of group or products of group Nivel 3 : use all filters



18
19
20
21
# File 'lib/bad_words.rb', line 18

def self.make_verify(str, nivel)
  words_define = load_words(nivel)
  verify_string(str, words_define.split(' '))
end

.verify_string(str, bad_words) ⇒ Object



29
30
31
32
# File 'lib/bad_words.rb', line 29

def self.verify_string(str, bad_words)
  str_broken = str.downcase.split(' ')
  str_broken.size() != (str_broken - bad_words).size()  
end