word_filter 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/word_filter.rb CHANGED
@@ -22,7 +22,7 @@ module WordFilter
22
22
  @filterLevel = NONE
23
23
  end
24
24
 
25
- attr_accessor :filterLevel
25
+ attr_accessor :filterLevel, :goodWords, :badWordsRegex
26
26
 
27
27
  def filterInit(dictionaryFile, badwordslist)
28
28
  @goodWords = loadDictionary(dictionaryFile)
@@ -1,3 +1,3 @@
1
1
  module WordFilter
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,51 @@
1
+ require 'word_filter'
2
+
3
+ describe WordFilter, 'load files' do
4
+ it 'should be able to load external dictionary files' do
5
+ filter = WordFilter::Filter.new
6
+ filter.filterInit("lib/dictionary.txt", "lib/badwords.txt")
7
+ end
8
+
9
+ it 'should return an array of words from the dictionary file' do
10
+ filter = WordFilter::Filter.new
11
+ filter.filterInit("lib/dictionary.txt", "lib/badwords.txt")
12
+ filter.goodWords.is_a?(Array).should be_true
13
+ end
14
+
15
+ it 'should return a regex from the badwords list' do
16
+ filter = WordFilter::Filter.new
17
+ filter.filterInit("lib/dictionary.txt", "lib/badwords.txt")
18
+ filter.badWordsRegex.is_a?(Regexp).should be_true
19
+ end
20
+ end
21
+
22
+ describe WordFilter, 'set filter level' do
23
+ it 'should be able to set a filter level' do
24
+ filter = WordFilter::Filter.new
25
+ filter.filterInit("lib/dictionary.txt", "lib/badwords.txt")
26
+ filter.filterLevel = WordFilter::Filter::SWAPPABLE_AND_REPEATED_VOWELS_INCLUDING_NONE
27
+ end
28
+ end
29
+
30
+ describe WordFilter, 'filter words' do
31
+ it 'should return zero if the input is a valid word' do
32
+ filter = WordFilter::Filter.new
33
+ filter.filterInit("lib/dictionary.txt", "lib/badwords.txt")
34
+ filter.filterLevel = WordFilter::Filter::SWAPPABLE_AND_REPEATED_VOWELS_INCLUDING_NONE
35
+ filter.filterString('hi').zero?.should be_true
36
+ end
37
+
38
+ it 'should not return 7 if the input is a bad word' do
39
+ filter = WordFilter::Filter.new
40
+ filter.filterInit("lib/dictionary.txt", "lib/badwords.txt")
41
+ filter.filterLevel = WordFilter::Filter::SWAPPABLE_AND_REPEATED_VOWELS_INCLUDING_NONE
42
+ filter.filterString('bitch').should == 7
43
+ end
44
+
45
+ it 'should not return nil if the input is a invalid word' do
46
+ filter = WordFilter::Filter.new
47
+ filter.filterInit("lib/dictionary.txt", "lib/badwords.txt")
48
+ filter.filterLevel = WordFilter::Filter::SWAPPABLE_AND_REPEATED_VOWELS_INCLUDING_NONE
49
+ filter.filterString('asdasd').should be_nil
50
+ end
51
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: word_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huascar Ona
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-01 00:00:00.000000000 Z
11
+ date: 2013-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -64,8 +64,11 @@ files:
64
64
  - LICENSE.txt
65
65
  - README.md
66
66
  - Rakefile
67
+ - lib/badwords.txt
68
+ - lib/dictionary.txt
67
69
  - lib/word_filter.rb
68
70
  - lib/word_filter/version.rb
71
+ - spec/word_filter_spec.rb
69
72
  - word_filter.gemspec
70
73
  homepage: ''
71
74
  licenses:
@@ -91,4 +94,5 @@ rubygems_version: 2.0.0.rc.2
91
94
  signing_key:
92
95
  specification_version: 4
93
96
  summary: A word filter gem
94
- test_files: []
97
+ test_files:
98
+ - spec/word_filter_spec.rb