naughty_words 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d85fccb7a94fab7fb39c18575bd3489c31ff0da5d0bfba585df0dda4fd49f560
4
- data.tar.gz: f2bbf7546a3e1c7ae53657060b39ef80cc4ec1a7eccae82cd74450f2dc6c7bd4
3
+ metadata.gz: 4d84f228f93cc6af5a7794aa4c42a56a45d1d8dd575982a687672cefa9991341
4
+ data.tar.gz: d2a64141e31b2a293fceef6fc5c58e8fe0a150db75c7d3be7227da5415948427
5
5
  SHA512:
6
- metadata.gz: a5cefb81ba419a3868697f08660b4931bda9ad09d68d609aa85adb40aeb4c286e96747cb30f5f7f289529da2009611e74db53bbf351609398b456630a44594bc
7
- data.tar.gz: 15b967ffd773daa055b5af6bb0395681b4a9669b9df9f642bb2f36871c6a218dd15b48ef15568c415ee4d03e52d2febaec1d8b2f8ed107bc053e00db5509991f
6
+ metadata.gz: eecf8555f6d2cfff3951c386caf6bdd428a0abaa9742ff552b773b33df938116553ffe859cbd2f365a332f428b6ce1be4743304512e948a668a474ce3d1ba1a1
7
+ data.tar.gz: 9817e7590058a2691b606acaecab6bff48a3a7abdd97ae3d914a96d53bf69c3fc4e2a2d943d7704902b6f7428ffb599c5fa771b732d3903413395628287c8cfe
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- naughty_words (0.1.0)
4
+ naughty_words (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -49,8 +49,25 @@ The `filter` method takes a `string:` argument and an optional `replacement:` ar
49
49
  NaughtyWords.filter(string: "hello asshole", replacement: "!")
50
50
  => "hello !!!!!!!"
51
51
  ```
52
+
52
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.
53
54
 
55
+ ### Validating in Rails example
56
+ 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
+
58
+ ```ruby
59
+ # app/models/user.rb
60
+
61
+ validates :username, uniqueness: true, presence: true # basic username validation
62
+ validate :username_profanity_check # our custom validator
63
+
64
+ ...
65
+
66
+ def username_profanity_check
67
+ errors.add(:username, "contains profanity") if NaughtyWords.check(string: username)
68
+ end
69
+ ```
70
+
54
71
  ## Development
55
72
 
56
73
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -4,8 +4,12 @@ module NaughtyWords
4
4
  class Base
5
5
  class << self
6
6
  def profanity?(string:)
7
- blacklist_file.each do |line|
8
- return true if string.include?(line.chomp)
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
@@ -13,21 +17,40 @@ module NaughtyWords
13
17
 
14
18
  def filter(string:, replacement:)
15
19
  # TODO: Fix filtering full words ending with 'ing' and repeated words such as 'fuckfuckfuck'
16
- blacklist_file.each do |line|
17
- word = line.chomp
20
+ deny_list_array.each do |line|
21
+ word = line
18
22
  string.gsub!(word, replacement * word.length)
19
23
  end
20
24
 
21
25
  string
22
26
  end
23
27
 
28
+ def add_to_list(list:, string:)
29
+ File.open(send(list), "a+") do |file|
30
+ file.puts(string)
31
+ end
32
+ end
33
+
34
+ def show_list(list:)
35
+ if list == "deny"
36
+ deny_list_array
37
+ else
38
+ allow_list_array
39
+ end
40
+ end
41
+
24
42
  private
25
43
 
26
- def blacklist_file
27
- txt_file = File.join(File.dirname(File.expand_path(__FILE__)), "config/en.txt")
28
- file = File.open(txt_file)
44
+ def deny_list_array
45
+ file = File.open(File.join(File.dirname(File.expand_path(__FILE__)), "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__)), "config/allow_list.txt"))
29
52
 
30
- @blacklist_file ||= file.readlines
53
+ @allow_list_array ||= File.readlines(file, chomp: true)
31
54
  end
32
55
  end
33
56
  end
@@ -0,0 +1,5 @@
1
+ cummings
2
+ baldasso
3
+ shitake
4
+ sex
5
+ scunthorpe
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NaughtyWords
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Arnold
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-19 00:00:00.000000000 Z
11
+ date: 2022-08-03 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/en.txt
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
Binary file