bad_word_detector 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +6 -0
- data/lib/bad_word_detector.rb +25 -4
- data/lib/bad_word_detector/version.rb +1 -1
- data/test/test_bad_word_detector.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -49,6 +49,12 @@ You can also set own rules:
|
|
49
49
|
finder = BadWordDetector.new rules, library, whitelist
|
50
50
|
```
|
51
51
|
|
52
|
+
Or you can use string filenames for YAML files of same format:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
finder = BadWordDetector.new 'my_rules.yaml', 'my_library.yaml', 'my_whitelist.yaml'
|
56
|
+
```
|
57
|
+
|
52
58
|
## Contributing
|
53
59
|
|
54
60
|
1. Fork it
|
data/lib/bad_word_detector.rb
CHANGED
@@ -20,8 +20,30 @@ class BadWordDetector
|
|
20
20
|
#
|
21
21
|
def initialize(rules = nil, library = nil, whitelist = nil)
|
22
22
|
confdir = File.expand_path(File.dirname(__FILE__) + "/conf")
|
23
|
-
|
24
|
-
|
23
|
+
rules_file = if rules.is_a? String
|
24
|
+
rules
|
25
|
+
else
|
26
|
+
"#{confdir}/rules.yaml"
|
27
|
+
end
|
28
|
+
library_file = if library.is_a? String
|
29
|
+
library
|
30
|
+
else
|
31
|
+
"#{confdir}/library.yaml"
|
32
|
+
end
|
33
|
+
whitelist_file = if whitelist.is_a? String
|
34
|
+
whitelist
|
35
|
+
else
|
36
|
+
"#{confdir}/whitelist.yaml"
|
37
|
+
end
|
38
|
+
unless rules.is_a? Hash
|
39
|
+
rules = YAML.load_file(rules_file)
|
40
|
+
end
|
41
|
+
unless library.is_a? Array
|
42
|
+
library = YAML.load_file(library_file)
|
43
|
+
end
|
44
|
+
unless whitelist.is_a? Array
|
45
|
+
whitelist = YAML.load_file(whitelist_file)
|
46
|
+
end
|
25
47
|
|
26
48
|
@rule_sets = rules.select do |key, _|
|
27
49
|
key.to_s.length == 1
|
@@ -43,9 +65,8 @@ class BadWordDetector
|
|
43
65
|
end
|
44
66
|
[key, rule]
|
45
67
|
end
|
46
|
-
|
47
68
|
@library = PrefixTree.new library
|
48
|
-
@whitelist = Whitelist.new whitelist
|
69
|
+
@whitelist = Whitelist.new whitelist
|
49
70
|
true
|
50
71
|
end
|
51
72
|
|