polite_text 0.2.0 → 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 +15 -11
- data/lib/polite_text.rb +19 -4
- data/lib/polite_text/base.rb +7 -3
- data/lib/polite_text/text_cleaner.rb +2 -3
- data/lib/polite_text/text_scanner.rb +2 -3
- data/lib/polite_text/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: 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
@@ -79,7 +79,7 @@ end
|
|
79
79
|
### Custom swear words list 🔞
|
80
80
|
Create a custom list in a **YAML** file following this format :
|
81
81
|
```
|
82
|
-
#
|
82
|
+
# custom_swear_words.yml
|
83
83
|
|
84
84
|
swear_words:
|
85
85
|
- gem
|
@@ -89,25 +89,29 @@ swear_words:
|
|
89
89
|
|
90
90
|
Place it where you want in your app, we recommend here : `./lib/polite_text/my_custom_swear_words.yml`
|
91
91
|
|
92
|
-
|
92
|
+
## Confirguration
|
93
93
|
|
94
|
-
|
94
|
+
📄 Create an initializer named `polite_text.rb`
|
95
|
+
|
96
|
+
✌️ Add the path to your custom swear words list like this :
|
95
97
|
|
96
|
-
### Remove or detect swear words 🤬 🙅♂️ 🙅♀️
|
97
98
|
```
|
98
|
-
#
|
99
|
+
# ./config/initializers/polite_text.rb
|
99
100
|
|
100
|
-
|
101
|
+
PoliteText.configure do |config|
|
102
|
+
config.custom_swear_words_path = "#{__dir__}/../../lib/polite_text/custom_swear_words.yml"
|
103
|
+
end
|
104
|
+
```
|
101
105
|
|
106
|
+
PoliteText is now configured with your custom list ✨💫
|
107
|
+
```
|
102
108
|
str = "This gem is a fucking big shit but let's try it"
|
103
109
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
PoliteText.be_polite!(str, custom_path)
|
110
|
+
<<<<<<< HEAD
|
111
|
+
PoliteText.be_polite!(str)
|
108
112
|
=> "This *** is a fucking *** shit *** let's try it"
|
109
113
|
|
110
|
-
PoliteText.is_polite?(str
|
114
|
+
PoliteText.is_polite?(str)
|
111
115
|
=> false
|
112
116
|
```
|
113
117
|
|
data/lib/polite_text.rb
CHANGED
@@ -4,12 +4,27 @@ require 'polite_text/text_cleaner'
|
|
4
4
|
|
5
5
|
module PoliteText
|
6
6
|
class << self
|
7
|
-
|
8
|
-
|
7
|
+
attr_accessor :custom_swear_words_path
|
8
|
+
|
9
|
+
def configure
|
10
|
+
yield self if block_given?
|
11
|
+
check_attrs
|
12
|
+
end
|
13
|
+
|
14
|
+
def be_polite!(text)
|
15
|
+
PoliteText::TextCleaner.new(text).clean!
|
9
16
|
end
|
10
17
|
|
11
|
-
def is_polite?(text
|
12
|
-
PoliteText::TextScanner.new(text
|
18
|
+
def is_polite?(text)
|
19
|
+
PoliteText::TextScanner.new(text).match_swear_word?
|
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
|
13
28
|
end
|
14
29
|
end
|
15
30
|
end
|
data/lib/polite_text/base.rb
CHANGED
@@ -2,17 +2,21 @@ require 'yaml'
|
|
2
2
|
|
3
3
|
module PoliteText
|
4
4
|
class Base
|
5
|
-
def swear_words
|
6
|
-
@swear_words ||= /\b(#{Regexp.union(swear_words_list
|
5
|
+
def swear_words
|
6
|
+
@swear_words ||= /\b(#{Regexp.union(swear_words_list).source})\b/
|
7
7
|
end
|
8
8
|
|
9
|
-
def swear_words_list(
|
9
|
+
def swear_words_list()
|
10
10
|
path = custom_swear_words_path ? custom_swear_words_path.to_s : swear_words_load_path
|
11
11
|
YAML.load_file(path)['swear_words']
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
+
def custom_swear_words_path
|
17
|
+
@custom_swear_words_path ||= PoliteText.custom_swear_words_path
|
18
|
+
end
|
19
|
+
|
16
20
|
# TODO: Implement dynamic locale with I18N
|
17
21
|
def locale
|
18
22
|
@locale ||= 'en'
|
@@ -2,15 +2,14 @@ module PoliteText
|
|
2
2
|
class TextCleaner < Base
|
3
3
|
attr_reader :text
|
4
4
|
|
5
|
-
def initialize(text
|
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
|
-
@custom_swear_words_path = custom_swear_words_path
|
10
9
|
end
|
11
10
|
|
12
11
|
def clean!
|
13
|
-
text.gsub!(swear_words
|
12
|
+
text.gsub!(swear_words, '***') || text
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
@@ -2,15 +2,14 @@ module PoliteText
|
|
2
2
|
class TextScanner < Base
|
3
3
|
attr_reader :text
|
4
4
|
|
5
|
-
def initialize(text
|
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
|
-
@custom_swear_words_path = custom_swear_words_path
|
10
9
|
end
|
11
10
|
|
12
11
|
def match_swear_word?
|
13
|
-
!@text.match?(swear_words
|
12
|
+
!@text.match?(swear_words)
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
data/lib/polite_text/version.rb
CHANGED
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
|