profanity_filter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -32,6 +32,9 @@ Non-Destructive (filters content when called, original text remains in the datab
32
32
  profanity_filter :foo, :bar, :method => 'hollow'
33
33
  #=> all letters except the first and last will be replaced
34
34
 
35
+ profanity_filter :foo, :bar, :method => 'stars'
36
+ #=> all letters will be replaced with *
37
+
35
38
  The non-destructive profanity_filter provides different versions of the filtered attribute:
36
39
  some_model.foo => 'filtered version'
37
40
  some_model.foo_original => 'non-filtered version'
@@ -50,6 +53,9 @@ Destructive (saves the filtered content to the database)
50
53
  profanity_filter! :foo, :bar, :method => 'hollow'
51
54
  #=> all letters except the first and last will be replaced
52
55
 
56
+ profanity_filter! :foo, :bar, :method => 'stars'
57
+ #=> all letters will be replaced with *
58
+
53
59
  === You can also use the filter directly:
54
60
 
55
61
  ProfanityFilter::Base.clean(text)
@@ -68,7 +74,6 @@ You can run the benchmarks via:
68
74
 
69
75
  == TODO
70
76
 
71
- * Turn this into a gem
72
77
  * May break ProfanityFilter out on it's own
73
78
  * Clean up dictionary implementation and substitution (suboptimal and messy)
74
79
  * Move benchmarks into a rake task
@@ -86,3 +91,5 @@ Created by Adam Bair (adam@intridea.com) of Intridea (http://www.intridea.com) i
86
91
  * Neil Ang - punctionation delimited profanity
87
92
  * Flinn Mueller - dynamic word list from method
88
93
  * Scott Stewert - additional dictionary words
94
+ * Nola Stowe - added stars profane filter
95
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -74,6 +74,8 @@ module ProfanityFilter
74
74
  when 'hollow'
75
75
  word[1..word.size-2] = '*' * (word.size-2) if word.size > 2
76
76
  word
77
+ when 'stars'
78
+ word = '*' * (word.size)
77
79
  else
78
80
  replacement_text
79
81
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{profanity_filter}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adam Bair"]
12
- s.date = %q{2011-04-11}
12
+ s.date = %q{2011-04-22}
13
13
  s.description = %q{Allows you to filter profanity using basic replacement or a dictionary term.}
14
14
  s.email = %q{adambair@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -24,6 +24,12 @@ module HollowPostHelper
24
24
  end
25
25
  end
26
26
 
27
+ module StarsPostHelper
28
+ class Post < ActiveRecord::Base
29
+ profanity_filter! :title, :body, :method => 'stars'
30
+ end
31
+ end
32
+
27
33
 
28
34
  class BasicProfanityFilterTest < Test::Unit::TestCase
29
35
  include BasicPostHelper
@@ -133,6 +139,35 @@ class HollowProfanityFilterTest < Test::Unit::TestCase
133
139
  assert_equal nil, p.body
134
140
  end
135
141
 
142
+ def test_it_should_handle_blank_fields_bug_9
143
+ p = Post.new({:title => "", :body => ""})
144
+ p.save
145
+ assert_equal "", p.title
146
+ assert_equal "", p.body
147
+ end
148
+ end
149
+
150
+ class StarsProfanityFilterTest < Test::Unit::TestCase
151
+ include StarsPostHelper
152
+
153
+ def profane_post(opts={})
154
+ Post.new({:title => 'A Fucking Title', :body => "This is some f-u-c-k-i-n-g shitty-post by a fucking user"}.merge(opts))
155
+ end
156
+
157
+ def test_it_should_filter_specified_fields
158
+ p = profane_post
159
+ p.save
160
+ assert_equal 'A ******* Title', p.title
161
+ assert_equal 'This is some ******* ******-post by a ******* user', p.body
162
+ end
163
+
164
+ def test_it_should_handle_nil_fields_bug_9
165
+ p = Post.new({:title => nil, :body => nil})
166
+ p.save
167
+ assert_equal nil, p.title
168
+ assert_equal nil, p.body
169
+ end
170
+
136
171
  def test_it_should_handle_blank_fields_bug_9
137
172
  p = Post.new({:title => "", :body => ""})
138
173
  p.save
@@ -139,3 +139,33 @@ class HollowProfanityFilterTest < Test::Unit::TestCase
139
139
  assert_equal 'happy-f**k', ProfanityFilter::Base.clean('happy-fuck', 'hollow')
140
140
  end
141
141
  end
142
+
143
+ class StarsProfanityFilterTest < Test::Unit::TestCase
144
+ def test_stars_profanity_filter_does_not_modify_clean_words
145
+ assert_equal 'happy', ProfanityFilter::Base.clean('happy', 'stars')
146
+ end
147
+
148
+ def test_stars_profanity_filter_does_not_modify_whitespace
149
+ assert_equal 'hello world', ProfanityFilter::Base.clean('hello world', 'stars')
150
+ assert_equal "hello \t world", ProfanityFilter::Base.clean("hello \t world", 'stars')
151
+ assert_equal "hello \n world", ProfanityFilter::Base.clean("hello \n world", 'stars')
152
+ end
153
+
154
+ def test_stars_profanity_filter_does_not_modify_special_characters
155
+ assert_equal 'happy ****', ProfanityFilter::Base.clean('happy fuck', 'stars')
156
+ assert_equal 'happy\'s', ProfanityFilter::Base.clean('happy\'s', 'stars')
157
+ assert_equal '****\'s', ProfanityFilter::Base.clean('fuck\'s', 'stars')
158
+ assert_equal '****?!', ProfanityFilter::Base.clean('fuck?!', 'stars')
159
+ end
160
+
161
+ def test_stars_profanity_filter_replaces_profane_words
162
+ assert_equal '****', ProfanityFilter::Base.clean('fuck', 'stars')
163
+ assert_equal '****', ProfanityFilter::Base.clean('FUCK', 'stars')
164
+ end
165
+
166
+ def test_stars_profanity_filter_replaces_punctuation_spaced_profane_words
167
+ assert_equal '****', ProfanityFilter::Base.clean('f-u-c-k', 'stars')
168
+ assert_equal '****', ProfanityFilter::Base.clean('f.u.c.k', 'stars')
169
+ assert_equal 'happy-****', ProfanityFilter::Base.clean('happy-fuck', 'stars')
170
+ end
171
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: profanity_filter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Bair
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-11 00:00:00 -04:00
18
+ date: 2011-04-22 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21