bad_words 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/bad_words.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "bad_words"
3
- s.version = "0.1.3"
3
+ s.version = "0.1.4"
4
4
  s.description = "A simple gem to clean string of bad words!"
5
5
  s.summary = "Bad Words"
6
6
  s.author = "Alessandro Neri"
data/lib/bad_words.rb CHANGED
@@ -2,30 +2,45 @@ require 'yaml'
2
2
 
3
3
  module BadWords
4
4
 
5
- #Str : String a ser limpa
5
+ #Str : String
6
6
  #Nivel 1 : clean bad words.
7
7
  #Nivel 2 : clean block words {exemplo name of concurrence, name of group or products of group}
8
8
  #Nivel 3 : use all filters
9
9
  def self.make_clean(str, nivel)
10
- words_define = ""
11
- load_words
12
- if nivel == 1 || nivel == 3
13
- words_define << @words['bad_words'] << " "
14
- end
15
- if nivel == 2 || nivel == 3
16
- words_define << @words['block_words']
17
- end
10
+ words_define = load_words(nivel)
18
11
  clean_string(str, words_define.split(' '))
19
12
  end
20
13
 
14
+ #Str : String
15
+ #Nivel 1 : verify bad words.
16
+ #Nivel 2 : verify block words {exemplo name of concurrence, name of group or products of group}
17
+ #Nivel 3 : use all filters
18
+ def self.make_verify(str, nivel)
19
+ words_define = load_words(nivel)
20
+ verify_string(str, words_define.split(' '))
21
+ end
22
+
21
23
  def self.clean_string(str, bad_words)
22
24
  str_broken = str.downcase.split(' ')
23
25
  bad_words.any? { |bw| str_broken.include?(bw) }
24
26
  (str_broken - bad_words).join(' ')
25
- end
27
+ end
28
+
29
+ def self.verify_string(str, bad_words)
30
+ str_broken = str.downcase.split(' ')
31
+ str_broken.size() != (str_broken - bad_words).size()
32
+ end
26
33
 
27
- def self.load_words
34
+ def self.load_words(nivel)
28
35
  @words = YAML.load_file("./config/words.yml")
36
+ words_define = ""
37
+ if nivel == 1 || nivel == 3
38
+ words_define << @words['bad_words'] << " "
39
+ end
40
+ if nivel == 2 || nivel == 3
41
+ words_define << @words['block_words']
42
+ end
43
+ words_define
29
44
  end
30
45
 
31
46
  end
@@ -14,4 +14,20 @@ class BadWordsTest < Test::Unit::TestCase
14
14
  def test_make_clean_nivel3
15
15
  assert_equal "good", BadWords.make_clean("CARALHO good iG", 3)
16
16
  end
17
+
18
+ def test_make_verify_nivel1
19
+ assert_equal true, BadWords.make_verify("CARALHO LEGAL", 1)
20
+ end
21
+
22
+ def test_make_verify_nivel2
23
+ assert_equal true, BadWords.make_verify("SITE iG", 2)
24
+ end
25
+
26
+ def test_make_verify_nivel3
27
+ assert_equal true, BadWords.make_verify("CARALHO good iG", 3)
28
+ end
29
+
30
+ def test_make_verify
31
+ assert_equal false, BadWords.make_verify("good", 3)
32
+ end
17
33
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bad_words
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alessandro Neri
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-05 00:00:00 -03:00
18
+ date: 2011-05-09 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21