polite_text 0.1.2 → 0.3.0
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/Gemfile.lock +1 -1
- data/README.md +76 -8
- data/lib/locales/en.yml +6 -0
- data/lib/polite_text.rb +15 -2
- data/lib/polite_text/base.rb +12 -7
- data/lib/polite_text/text_cleaner.rb +3 -9
- data/lib/polite_text/text_scanner.rb +2 -8
- data/lib/polite_text/version.rb +1 -1
- data/polite_text.gemspec +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: 6441b50cc047fa72c872b0b2f4e1bcaff686461d28738426251f3562e7507494
|
4
|
+
data.tar.gz: 5cec91bda68345fdc0af048107edaf971b32848f823e9f2e4f88f46524d608f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6d59fba6f064483e5ffe3494d02694790d1d15cc2710463c49a64f25f487886518e68e33f6f23e6ed4ebc9bf87047f23a9fee49f8fb7b06802aea202d0ae134
|
7
|
+
data.tar.gz: d76c2d3b3eb20b90b03ff2f05fa5eb277e5d7b36100aa8ae5cae1650a55582da9a2146f6b06b14b208b397b3f752cf92abb9ae154c2199fc8b2dbdc2bf20b4a4
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
|
6
6
|
PoliteText is making your users' input polite 👀
|
7
7
|
|
8
|
-
👉 Replace the swear words or execute callbacks if the input is not polite.
|
8
|
+
👉 Replace the swear words or execute callbacks if the input is not polite based on a default swear words list or your own.
|
9
9
|
|
10
|
-
## Installation
|
10
|
+
## Installation 👨💻 👩💻
|
11
11
|
|
12
12
|
Add this line to your application's Gemfile:
|
13
13
|
|
@@ -23,7 +23,10 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
$ gem install polite_text
|
25
25
|
|
26
|
-
## Usage
|
26
|
+
## Usage with the default swear words list 🌝
|
27
|
+
|
28
|
+
### Swear words 🔞
|
29
|
+
PoliteText has a default list of forbidden words, this list includes the most common swear words used on the web. You can acces the list of swear words [here](https://github.com/OpenGems/polite_text/blob/master/lib/locales/en.yml).
|
27
30
|
|
28
31
|
### Remove swear words 🤬
|
29
32
|
```
|
@@ -32,7 +35,6 @@ include PoliteText
|
|
32
35
|
str = "This gem is a fucking big shit but let's try it"
|
33
36
|
|
34
37
|
PoliteText.be_polite!(str)
|
35
|
-
|
36
38
|
=> "This gem is a *** big *** but let's try it"
|
37
39
|
```
|
38
40
|
|
@@ -43,20 +45,86 @@ include PoliteText
|
|
43
45
|
str = "This gem is a fucking big shit but let's try it"
|
44
46
|
|
45
47
|
PoliteText.is_polite?(str)
|
48
|
+
=> false
|
49
|
+
```
|
50
|
+
|
51
|
+
### Example for an Article model
|
52
|
+
|
53
|
+
```
|
54
|
+
# == Schema Information
|
55
|
+
#
|
56
|
+
# Table name: articles
|
57
|
+
#
|
58
|
+
# id :bigint not null, primary key
|
59
|
+
# text :string default(""), not null
|
60
|
+
# created_at :datetime not null
|
61
|
+
# updated_at :datetime not null
|
62
|
+
#
|
63
|
+
|
64
|
+
class Article < ApplicationRecord
|
65
|
+
include PoliteText
|
66
|
+
|
67
|
+
# Callbacks
|
68
|
+
before_save :make_text_polite
|
69
|
+
|
70
|
+
# Methods
|
71
|
+
def make_text_polite
|
72
|
+
PoliteText.be_polite!(text)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
## Usage with custom swear words list 🌞
|
78
|
+
|
79
|
+
### Custom swear words list 🔞
|
80
|
+
Create a custom list in a **YAML** file following this format :
|
81
|
+
```
|
82
|
+
# custom_swear_words.yml
|
83
|
+
|
84
|
+
swear_words:
|
85
|
+
- gem
|
86
|
+
- big
|
87
|
+
- but
|
88
|
+
```
|
89
|
+
|
90
|
+
Place it where you want in your app, we recommend here : `./lib/polite_text/my_custom_swear_words.yml`
|
46
91
|
|
92
|
+
## Confirguration
|
93
|
+
|
94
|
+
📄 Create an initializer named `polite_text.rb`
|
95
|
+
|
96
|
+
✌️ Add the path to your custom swear words list like this :
|
97
|
+
|
98
|
+
```
|
99
|
+
# ./config/initializers/polite_text.rb
|
100
|
+
|
101
|
+
PoliteText.configure do |config|
|
102
|
+
config.custom_swear_words_path = "#{__dir__}/../../lib/polite_text/custom_swear_words.yml"
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
PoliteText is now configured with your custom list ✨💫
|
107
|
+
```
|
108
|
+
str = "This gem is a fucking big shit but let's try it"
|
109
|
+
|
110
|
+
<<<<<<< HEAD
|
111
|
+
PoliteText.be_polite!(str)
|
112
|
+
=> "This *** is a fucking *** shit *** let's try it"
|
113
|
+
|
114
|
+
PoliteText.is_polite?(str)
|
47
115
|
=> false
|
48
116
|
```
|
49
117
|
|
118
|
+
|
50
119
|
## Contributing
|
51
120
|
|
52
121
|
Bug reports and pull requests are welcome on GitHub at https://github.com/OpenGems/polite_text.
|
53
122
|
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
|
54
123
|
|
55
124
|
### Todo 💪
|
56
|
-
- [ ]
|
57
|
-
- [ ]
|
58
|
-
- [ ]
|
59
|
-
- [ ] Add swear words from multiple languages
|
125
|
+
- [ ] Manage locales with I18N for default swear words lists by country.
|
126
|
+
- [ ] Add default swear words lists from multiple languages.
|
127
|
+
- [ ] Improve the default swear words list and keeping it short.
|
60
128
|
|
61
129
|
## License
|
62
130
|
|
data/lib/locales/en.yml
CHANGED
@@ -4,18 +4,24 @@ swear_words:
|
|
4
4
|
- fuck
|
5
5
|
- fuckyou
|
6
6
|
- fucker
|
7
|
+
- fuckers
|
7
8
|
- fucking
|
8
9
|
- dick head
|
9
10
|
- dick
|
10
11
|
- dickhole
|
11
12
|
- cock
|
12
13
|
- asshole
|
14
|
+
- assholes
|
13
15
|
- son of a bitch
|
14
16
|
- bitch
|
17
|
+
- bitches
|
15
18
|
- biatch
|
16
19
|
- whore
|
20
|
+
- whores
|
17
21
|
- bastard
|
22
|
+
- bastards
|
18
23
|
- wanker
|
24
|
+
- wankers
|
19
25
|
- shit
|
20
26
|
- piss
|
21
27
|
- pussy
|
data/lib/polite_text.rb
CHANGED
@@ -3,9 +3,14 @@ require 'polite_text/text_scanner'
|
|
3
3
|
require 'polite_text/text_cleaner'
|
4
4
|
|
5
5
|
module PoliteText
|
6
|
-
class Error < StandardError; end
|
7
|
-
|
8
6
|
class << self
|
7
|
+
attr_accessor :custom_swear_words_path
|
8
|
+
|
9
|
+
def configure
|
10
|
+
yield self if block_given?
|
11
|
+
check_attrs
|
12
|
+
end
|
13
|
+
|
9
14
|
def be_polite!(text)
|
10
15
|
PoliteText::TextCleaner.new(text).clean!
|
11
16
|
end
|
@@ -13,5 +18,13 @@ module PoliteText
|
|
13
18
|
def is_polite?(text)
|
14
19
|
PoliteText::TextScanner.new(text).match_swear_word?
|
15
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def check_attrs
|
25
|
+
unless custom_swear_words_path.is_a?(::String)
|
26
|
+
raise(ArgumentError, 'Invalid path to your custom swear words list.')
|
27
|
+
end
|
28
|
+
end
|
16
29
|
end
|
17
30
|
end
|
data/lib/polite_text/base.rb
CHANGED
@@ -6,19 +6,24 @@ module PoliteText
|
|
6
6
|
@swear_words ||= /\b(#{Regexp.union(swear_words_list).source})\b/
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def swear_words_list
|
14
|
-
YAML.load_file(swear_words_load_path)['swear_words']
|
9
|
+
def swear_words_list()
|
10
|
+
path = custom_swear_words_path ? custom_swear_words_path.to_s : swear_words_load_path
|
11
|
+
YAML.load_file(path)['swear_words']
|
15
12
|
end
|
16
13
|
|
17
14
|
private
|
18
15
|
|
19
|
-
|
16
|
+
def custom_swear_words_path
|
17
|
+
@custom_swear_words_path ||= PoliteText.custom_swear_words_path
|
18
|
+
end
|
19
|
+
|
20
|
+
# TODO: Implement dynamic locale with I18N
|
20
21
|
def locale
|
21
22
|
@locale ||= 'en'
|
22
23
|
end
|
24
|
+
|
25
|
+
def swear_words_load_path
|
26
|
+
"#{__dir__}/../locales/#{locale}.yml"
|
27
|
+
end
|
23
28
|
end
|
24
29
|
end
|
@@ -3,19 +3,13 @@ module PoliteText
|
|
3
3
|
attr_reader :text
|
4
4
|
|
5
5
|
def initialize(text)
|
6
|
-
|
6
|
+
raise ArgumentError.new('The text can not be nil') if text.nil?
|
7
7
|
|
8
|
-
|
8
|
+
@text = text.to_s
|
9
9
|
end
|
10
10
|
|
11
11
|
def clean!
|
12
|
-
text.gsub!(swear_words, '***')
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def validate_text!
|
18
|
-
raise ArgumentError.new('The text can not be empty') if @text.empty?
|
12
|
+
text.gsub!(swear_words, '***') || text
|
19
13
|
end
|
20
14
|
end
|
21
15
|
end
|
@@ -3,19 +3,13 @@ module PoliteText
|
|
3
3
|
attr_reader :text
|
4
4
|
|
5
5
|
def initialize(text)
|
6
|
-
|
6
|
+
raise ArgumentError.new('The text can not be nil') if text.nil?
|
7
7
|
|
8
|
-
|
8
|
+
@text = text.to_s
|
9
9
|
end
|
10
10
|
|
11
11
|
def match_swear_word?
|
12
12
|
!@text.match?(swear_words)
|
13
13
|
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def validate_text!
|
18
|
-
raise ArgumentError.new('The text can not be empty') if @text.empty?
|
19
|
-
end
|
20
14
|
end
|
21
15
|
end
|
data/lib/polite_text/version.rb
CHANGED
data/polite_text.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
|
18
18
|
# Specify which files should be added to the gem when it is released.
|
19
19
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
-
spec.files = Dir.chdir(File.expand_path(
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
21
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
22
|
end
|
23
23
|
spec.bindir = 'exe'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polite_text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DumasOlivier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|