wordfilter 0.2.6
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.
- checksums.yaml +7 -0
- data/lib/badwords.json +55 -0
- data/lib/wordfilter.rb +48 -0
- data/test/wordfilter_test.rb +43 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bacf3448e222dac61c2dc9f317d1615846c21d98
|
4
|
+
data.tar.gz: 532ae6ef880ac7fb3156ff70e88b3641c523cada
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d4190aaf7950c6f37c5f7cbe5b9435bbb95959bb23be2846e556a64cfed94119733f46a9332d3fe3f0d530c2248a90886ff8a3b0d60a42f4ff4bb4752f62489
|
7
|
+
data.tar.gz: ee54c97fbcf1b05a94621b9d4c97d6e6012ed3c5801d51064bf776074181b2977e1062184a277492462fa790554d289e8d20d688353c204c791de4ba35d64de8
|
data/lib/badwords.json
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
[
|
2
|
+
"beeyotch",
|
3
|
+
"biatch",
|
4
|
+
"bitch",
|
5
|
+
"chinaman",
|
6
|
+
"chinamen",
|
7
|
+
"chink",
|
8
|
+
"crip",
|
9
|
+
"cunt",
|
10
|
+
"dago",
|
11
|
+
"daygo",
|
12
|
+
"dego",
|
13
|
+
"dick",
|
14
|
+
"douchebag",
|
15
|
+
"dyke",
|
16
|
+
"fag",
|
17
|
+
"fatass",
|
18
|
+
"fatso",
|
19
|
+
"gash",
|
20
|
+
"gimp",
|
21
|
+
"golliwog",
|
22
|
+
"gook",
|
23
|
+
"gyp",
|
24
|
+
"homo",
|
25
|
+
"hooker",
|
26
|
+
"jap",
|
27
|
+
"kike",
|
28
|
+
"kraut",
|
29
|
+
"lame",
|
30
|
+
"lardass",
|
31
|
+
"lesbo",
|
32
|
+
"negro",
|
33
|
+
"nigga",
|
34
|
+
"nigger",
|
35
|
+
"paki",
|
36
|
+
"pickaninny",
|
37
|
+
"pussy",
|
38
|
+
"raghead",
|
39
|
+
"retard",
|
40
|
+
"shemale",
|
41
|
+
"skank",
|
42
|
+
"slut",
|
43
|
+
"spade",
|
44
|
+
"spic",
|
45
|
+
"spook",
|
46
|
+
"tard",
|
47
|
+
"tits",
|
48
|
+
"titt",
|
49
|
+
"trannies",
|
50
|
+
"tranny",
|
51
|
+
"twat",
|
52
|
+
"wetback",
|
53
|
+
"whore",
|
54
|
+
"wop"
|
55
|
+
]
|
data/lib/wordfilter.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Wordfilter
|
4
|
+
BadWordsFileName = File.dirname(__FILE__) + "/badwords.json"
|
5
|
+
@@blacklist = nil
|
6
|
+
|
7
|
+
def self.init_first_time
|
8
|
+
return if(!@@blacklist.nil?)
|
9
|
+
self.init
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.init
|
13
|
+
badwords_file = File.read(BadWordsFileName)
|
14
|
+
@@blacklist = JSON.parse(badwords_file)
|
15
|
+
@@blacklist.map!(&:downcase)
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.blacklisted? string
|
20
|
+
self.init_first_time
|
21
|
+
|
22
|
+
string_to_test = string.downcase
|
23
|
+
|
24
|
+
@@blacklist.each{|word|
|
25
|
+
return true if string_to_test.include? word
|
26
|
+
}
|
27
|
+
|
28
|
+
return false
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.add_words words
|
32
|
+
self.init_first_time
|
33
|
+
words.map!(&:downcase)
|
34
|
+
@@blacklist += words
|
35
|
+
return
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.remove_word word
|
39
|
+
self.init_first_time
|
40
|
+
@@blacklist.delete word.downcase
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.clear_list
|
45
|
+
@@blacklist = []
|
46
|
+
return
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib/')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'wordfilter'
|
5
|
+
|
6
|
+
class WordfilterTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
Wordfilter.init
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_detects_bad_words_in_a_string
|
14
|
+
assert(Wordfilter::blacklisted?("this string contains the word skank"), "skank should be true")
|
15
|
+
assert(Wordfilter::blacklisted?("this string contains the word SkAnK"), "SkAnK should be true")
|
16
|
+
assert(Wordfilter::blacklisted?("tthis string contains the wordskank"), "wordskank should be true")
|
17
|
+
assert(Wordfilter::blacklisted?("this string contains the skankword"), "skankword should be true")
|
18
|
+
refute(Wordfilter::blacklisted?("this string is clean!"), "should be false")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_add_word_to_blacklist
|
22
|
+
Wordfilter::add_words(['clean'])
|
23
|
+
assert(Wordfilter::blacklisted?("this string was clean!"), "Failed to blacklist a string containing a new bad word.")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_added_words_checked_case_insensitively
|
27
|
+
Wordfilter::add_words(['CLEAN'])
|
28
|
+
assert(Wordfilter::blacklisted?("this string was clean!"), "Failed to blacklist a string containing a new bad word because of casing differences.")
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_clear_blacklist
|
32
|
+
Wordfilter::clear_list
|
33
|
+
refute(Wordfilter::blacklisted?("this string contains the word skank"), "Cleared word list still blacklisting strings.")
|
34
|
+
Wordfilter::add_words(['skank'])
|
35
|
+
assert(Wordfilter::blacklisted?("this string contains the word skank"), "Failed to blacklist a string containing a new bad word.")
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_remove_single_word_from_blacklist
|
39
|
+
assert(Wordfilter::blacklisted?("I have a prescription."), "Prescription should be blacklisted.")
|
40
|
+
Wordfilter::remove_word "crip"
|
41
|
+
refute(Wordfilter::blacklisted?("I have a prescription."), "Prescription should no longer be blacklisted.")
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wordfilter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Darius Kazemi
|
8
|
+
- Eli Brody
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-01-30 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: |
|
15
|
+
Wordfilter is a small library that can check a string for blacklisted words.
|
16
|
+
It comes with a pre-defined list of words, but you can add your own.
|
17
|
+
email:
|
18
|
+
- darius.kazemi@gmail.com
|
19
|
+
- brodyeli@gmail.com
|
20
|
+
executables: []
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- lib/wordfilter.rb
|
25
|
+
- lib/badwords.json
|
26
|
+
- test/wordfilter_test.rb
|
27
|
+
homepage: https://github.com/dariusk/wordfilter
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.0.14
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: A small module meant for use in text generators that lets you filter strings
|
51
|
+
for bad words.
|
52
|
+
test_files:
|
53
|
+
- test/wordfilter_test.rb
|