bad_word_detector 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,8 +8,9 @@ class State
8
8
  @length = 0
9
9
  @weight = 1
10
10
 
11
- path.each do |rule|
11
+ path.each_index do |index|
12
12
  # puts item.inspect
13
+ rule = path[index]
13
14
  @text += rule.symbol
14
15
  @length += rule.length
15
16
  @weight *= rule.weight
@@ -17,6 +18,12 @@ class State
17
18
  end
18
19
 
19
20
  def append(rule)
21
+ last_char_index = @path.rindex {|r| r.symbol != '' }
22
+ rule = if last_char_index and @path[last_char_index].symbol == rule.symbol and rule.symbol != ''
23
+ Rule.new rule.char, '', 1
24
+ else
25
+ rule
26
+ end
20
27
  State.new @path + [rule], State.get_library(rule ? rule.symbol : '', @library)
21
28
  end
22
29
 
@@ -38,4 +45,4 @@ class State
38
45
  library[symbol]
39
46
  end
40
47
  end
41
- end
48
+ end
@@ -1,3 +1,3 @@
1
1
  class BadWordDetector
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -58,11 +58,27 @@ class TestBadWordDetector < Test::Unit::TestCase
58
58
  assert_equal true, word.white?
59
59
  end
60
60
  def test_false_positive_in_text
61
- word = finder.find("Thing as is!", true)
61
+ word = finder.find("jackass", true)
62
62
  assert_not_nil word
63
63
  assert_equal true, word.white?
64
64
  assert_equal "ass", word.word
65
65
  end
66
+ def test_repeats
67
+ word = finder.find("fuuuuuuuck")
68
+ assert_not_nil word
69
+ assert_equal "fuuuuuuuck", word.text
70
+ assert_equal "fuck", word.word
71
+ assert_equal "fuuuuuuuck", word.source
72
+ assert_equal 0, word.index
73
+ end
74
+ def test_repeats_replaces
75
+ word = finder.find("fuuu|_|uuuck")
76
+ assert_not_nil word
77
+ assert_equal "fuuu|_|uuuck", word.text
78
+ assert_equal "fuck", word.word
79
+ assert_equal "fuuu|_|uuuck", word.source
80
+ assert_equal 0, word.index
81
+ end
66
82
  end
67
83
 
68
84
  class Finder
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.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-15 00:00:00.000000000 Z
12
+ date: 2013-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yard