naughty_words 0.1.1 → 0.1.3
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 +4 -4
- data/.rubocop.yml +14 -0
- data/Gemfile.lock +2 -2
- data/README.md +20 -1
- data/lib/naughty_words/base.rb +33 -9
- data/lib/naughty_words/config/allow_list.txt +5 -0
- data/lib/naughty_words/config/{en.txt → deny_list.txt} +1 -4
- data/lib/naughty_words/version.rb +1 -1
- data/lib/naughty_words.rb +12 -0
- metadata +4 -4
- data/naughty_words-0.1.0.gem +0 -0
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/.rubocop.yml
CHANGED
@@ -15,3 +15,17 @@ Layout/LineLength:
|
|
15
15
|
Style/Documentation:
|
16
16
|
Description: 'Document classes and non-namespace modules.'
|
17
17
|
Enabled: false
|
18
|
+
|
19
|
+
Metrics/BlockLength:
|
20
|
+
CountComments: true
|
21
|
+
Max: 25
|
22
|
+
Exclude:
|
23
|
+
- 'spec/**/*'
|
24
|
+
- 'config/**/*'
|
25
|
+
- 'lib/tasks/**/*'
|
26
|
+
|
27
|
+
Style/FrozenStringLiteralComment:
|
28
|
+
Description: >-
|
29
|
+
Add the frozen_string_literal comment to the top of files
|
30
|
+
to help transition from Ruby 2.3.0 to Ruby 3.0.
|
31
|
+
Enabled: false
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -45,11 +45,30 @@ 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
|
+
|
57
|
+
### Validating in Rails example
|
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.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
# app/models/user.rb
|
62
|
+
|
63
|
+
validates :username, uniqueness: true, presence: true # basic username validation
|
64
|
+
validate :username_profanity_check # our custom validator
|
65
|
+
|
66
|
+
...
|
67
|
+
|
68
|
+
def username_profanity_check
|
69
|
+
errors.add(:username, "contains profanity") if NaughtyWords.check(string: username)
|
70
|
+
end
|
71
|
+
```
|
53
72
|
|
54
73
|
## Development
|
55
74
|
|
data/lib/naughty_words/base.rb
CHANGED
@@ -4,30 +4,54 @@ module NaughtyWords
|
|
4
4
|
class Base
|
5
5
|
class << self
|
6
6
|
def profanity?(string:)
|
7
|
-
|
8
|
-
return
|
7
|
+
allow_list_array.each do |line|
|
8
|
+
return false if string.include?(line)
|
9
|
+
end
|
10
|
+
|
11
|
+
deny_list_array.each do |line|
|
12
|
+
return true if string.include?(line)
|
9
13
|
end
|
10
14
|
|
11
15
|
false
|
12
16
|
end
|
13
17
|
|
14
18
|
def filter(string:, replacement:)
|
15
|
-
|
16
|
-
|
17
|
-
word = line.chomp
|
19
|
+
deny_list_array.each do |line|
|
20
|
+
word = line
|
18
21
|
string.gsub!(word, replacement * word.length)
|
19
22
|
end
|
20
23
|
|
21
24
|
string
|
22
25
|
end
|
23
26
|
|
27
|
+
def add_to_list(list:, string:)
|
28
|
+
File.open(send(list), "a+") do |file|
|
29
|
+
file.puts(string)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def show_list(list:)
|
34
|
+
if list == "deny"
|
35
|
+
deny_list_array
|
36
|
+
else
|
37
|
+
allow_list_array
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
24
41
|
private
|
25
42
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
43
|
+
def deny_list_array
|
44
|
+
file = File.open(File.join(File.dirname(File.expand_path(__FILE__)),
|
45
|
+
"config/deny_list.txt"))
|
46
|
+
|
47
|
+
@deny_list_array ||= File.readlines(file, chomp: true)
|
48
|
+
end
|
49
|
+
|
50
|
+
def allow_list_array
|
51
|
+
file = File.open(File.join(File.dirname(File.expand_path(__FILE__)),
|
52
|
+
"config/allow_list.txt"))
|
29
53
|
|
30
|
-
@
|
54
|
+
@allow_list_array ||= File.readlines(file, chomp: true)
|
31
55
|
end
|
32
56
|
end
|
33
57
|
end
|
@@ -10,7 +10,6 @@ apeshit
|
|
10
10
|
arsehole
|
11
11
|
asshole
|
12
12
|
assmunch
|
13
|
-
ass
|
14
13
|
auto erotic
|
15
14
|
autoerotic
|
16
15
|
babeland
|
@@ -96,10 +95,9 @@ cornhole
|
|
96
95
|
coon
|
97
96
|
coons
|
98
97
|
creampie
|
99
|
-
cum
|
100
|
-
cumming
|
101
98
|
cumshot
|
102
99
|
cumshots
|
100
|
+
cumming
|
103
101
|
cunnilingus
|
104
102
|
cunting
|
105
103
|
cunt
|
@@ -398,7 +396,6 @@ whore
|
|
398
396
|
worldsex
|
399
397
|
wrapping men
|
400
398
|
wrinkled starfish
|
401
|
-
xx
|
402
399
|
xxx
|
403
400
|
yaoi
|
404
401
|
yellow showers
|
data/lib/naughty_words.rb
CHANGED
@@ -13,5 +13,17 @@ module NaughtyWords
|
|
13
13
|
def filter(string:, replacement: "*")
|
14
14
|
Base.filter(string: string, replacement: replacement)
|
15
15
|
end
|
16
|
+
|
17
|
+
def add_to_deny_list(string:)
|
18
|
+
Base.add_to_list(list: "deny_list_file", string: string)
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_to_allow_list(string:)
|
22
|
+
Base.add_to_list(list: "allow_list_file", string: string)
|
23
|
+
end
|
24
|
+
|
25
|
+
def show_list(list:)
|
26
|
+
Base.show_list(list: list)
|
27
|
+
end
|
16
28
|
end
|
17
29
|
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.
|
@@ -31,9 +31,9 @@ files:
|
|
31
31
|
- bin/setup
|
32
32
|
- lib/naughty_words.rb
|
33
33
|
- lib/naughty_words/base.rb
|
34
|
-
- lib/naughty_words/config/
|
34
|
+
- lib/naughty_words/config/allow_list.txt
|
35
|
+
- lib/naughty_words/config/deny_list.txt
|
35
36
|
- lib/naughty_words/version.rb
|
36
|
-
- naughty_words-0.1.0.gem
|
37
37
|
homepage: https://github.com/jaarnie/naughty_words
|
38
38
|
licenses:
|
39
39
|
- MIT
|
data/naughty_words-0.1.0.gem
DELETED
Binary file
|