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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d85fccb7a94fab7fb39c18575bd3489c31ff0da5d0bfba585df0dda4fd49f560
4
- data.tar.gz: f2bbf7546a3e1c7ae53657060b39ef80cc4ec1a7eccae82cd74450f2dc6c7bd4
3
+ metadata.gz: d57b97899577e770df8be076a260356960598772f8b35d14b70f0c1fcd346ddf
4
+ data.tar.gz: '093ef5e005fb5c73516ce20d78ec205b37b814232ac62ebb6cf3b2aac40380b0'
5
5
  SHA512:
6
- metadata.gz: a5cefb81ba419a3868697f08660b4931bda9ad09d68d609aa85adb40aeb4c286e96747cb30f5f7f289529da2009611e74db53bbf351609398b456630a44594bc
7
- data.tar.gz: 15b967ffd773daa055b5af6bb0395681b4a9669b9df9f642bb2f36871c6a218dd15b48ef15568c415ee4d03e52d2febaec1d8b2f8ed107bc053e00db5509991f
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- naughty_words (0.1.0)
4
+ naughty_words (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -58,4 +58,4 @@ DEPENDENCIES
58
58
  rubocop (~> 1.21)
59
59
 
60
60
  BUNDLED WITH
61
- 2.2.30
61
+ 2.3.24
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
- Note: Current, this is comically easy to circumvent. String like "shitshitshit" will only filter out the first match, returning "*****shitshit". A fix is enroute.
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
 
@@ -4,30 +4,54 @@ 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
12
16
  end
13
17
 
14
18
  def filter(string:, replacement:)
15
- # TODO: Fix filtering full words ending with 'ing' and repeated words such as 'fuckfuckfuck'
16
- blacklist_file.each do |line|
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 blacklist_file
27
- txt_file = File.join(File.dirname(File.expand_path(__FILE__)), "config/en.txt")
28
- file = File.open(txt_file)
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
- @blacklist_file ||= file.readlines
54
+ @allow_list_array ||= File.readlines(file, chomp: true)
31
55
  end
32
56
  end
33
57
  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.3"
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.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: 2022-05-19 00:00:00.000000000 Z
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/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