naughty_words 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +4 -2
- data/lib/naughty_words/base.rb +4 -3
- data/lib/naughty_words/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d57b97899577e770df8be076a260356960598772f8b35d14b70f0c1fcd346ddf
|
4
|
+
data.tar.gz: '093ef5e005fb5c73516ce20d78ec205b37b814232ac62ebb6cf3b2aac40380b0'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 684f809efaac39ce2261e50f5d63886ab50e310a6192295c22745d3f3082551d2acb5d9e8bd9822947c78a02bfee54a730387dc5fc2a572c9a5a372036b746cc
|
7
|
+
data.tar.gz: c032f4abd47b5b1990540dbaa914234912ea80d2ae2980f5d6238f661f463072ce654e3600526bc489c4f180b7426368f0f8208881b0850db7ee21b06cc2e038
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -45,13 +45,15 @@ The `filter` method takes a `string:` argument and an optional `replacement:` ar
|
|
45
45
|
NaughtyWords.filter(string: "hello asshole")
|
46
46
|
=> "hello *******"
|
47
47
|
|
48
|
+
# you can filter out consecutive naughty words
|
49
|
+
NaughtyWords.filter(string: "shitshitshityeah")
|
50
|
+
=> "************yeah"
|
51
|
+
|
48
52
|
# you can use in your own filter character by passing it in as an argument ("*" is by default)
|
49
53
|
NaughtyWords.filter(string: "hello asshole", replacement: "!")
|
50
54
|
=> "hello !!!!!!!"
|
51
55
|
```
|
52
56
|
|
53
|
-
Note: Current, this is comically easy to circumvent. String like "shitshitshit" will only filter out the first match, returning "*****shitshit". A fix is enroute.
|
54
|
-
|
55
57
|
### Validating in Rails example
|
56
58
|
We can use a custom validator in our User model to make sure a user cannot sign up with a username containing profanities in tandem with our normal `validates` methods.
|
57
59
|
|
data/lib/naughty_words/base.rb
CHANGED
@@ -16,7 +16,6 @@ module NaughtyWords
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def filter(string:, replacement:)
|
19
|
-
# TODO: Fix filtering full words ending with 'ing' and repeated words such as 'fuckfuckfuck'
|
20
19
|
deny_list_array.each do |line|
|
21
20
|
word = line
|
22
21
|
string.gsub!(word, replacement * word.length)
|
@@ -42,13 +41,15 @@ module NaughtyWords
|
|
42
41
|
private
|
43
42
|
|
44
43
|
def deny_list_array
|
45
|
-
file = File.open(File.join(File.dirname(File.expand_path(__FILE__)),
|
44
|
+
file = File.open(File.join(File.dirname(File.expand_path(__FILE__)),
|
45
|
+
"config/deny_list.txt"))
|
46
46
|
|
47
47
|
@deny_list_array ||= File.readlines(file, chomp: true)
|
48
48
|
end
|
49
49
|
|
50
50
|
def allow_list_array
|
51
|
-
file = File.open(File.join(File.dirname(File.expand_path(__FILE__)),
|
51
|
+
file = File.open(File.join(File.dirname(File.expand_path(__FILE__)),
|
52
|
+
"config/allow_list.txt"))
|
52
53
|
|
53
54
|
@allow_list_array ||= File.readlines(file, chomp: true)
|
54
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: naughty_words
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Arnold
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This gem will detect simple profanity and can substitute them with a
|
14
14
|
specified replacement.
|