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 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
@@ -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
- rules ||= YAML.load_file("#{confdir}/rules.yaml")
24
- library ||= YAML.load_file("#{confdir}/library.yaml")
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 || YAML.load_file("#{confdir}/whitelist.yaml")
69
+ @whitelist = Whitelist.new whitelist
49
70
  true
50
71
  end
51
72
 
@@ -1,3 +1,3 @@
1
1
  class BadWordDetector
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -67,6 +67,6 @@ end
67
67
 
68
68
  class Finder
69
69
  def self.finder
70
- @finder ||= BadWordDetector.new YAML.load_file(File.dirname(__FILE__)+"/rules.yaml")
70
+ @finder ||= BadWordDetector.new File.dirname(__FILE__)+"/rules.yaml"
71
71
  end
72
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bad_word_detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: