polite_text 0.1.2 → 0.1.21
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 +34 -4
- data/lib/locales/en.yml +6 -0
- data/lib/polite_text.rb +0 -2
- data/lib/polite_text/base.rb +1 -1
- data/lib/polite_text/text_cleaner.rb +2 -8
- data/lib/polite_text/text_scanner.rb +2 -8
- data/lib/polite_text/version.rb +1 -1
- data/polite_text.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 574591328155e7985751a85bfdb2610376f9c976b4d0a589c1d735ec9bfb9816
|
4
|
+
data.tar.gz: b0f61d51a49c6882dbd666a495b20b2e0f12a5a2ae716c20350b2739e3910afe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d678889edb60886cfb83f6a186335e6371238cd45669eec435f1cf0f52f981cd074cfa04cbb8181243314edb68c371b0e9ca45805d9184719a1b8f1518839064
|
7
|
+
data.tar.gz: 705cbb3d6f397a4292aa858fc734d3dea33d7fa4c6989d4d848b3968948b2f9b57ca367c076a00968eafb9d931b58ab823b24e3c0b2421594ee4c5f13ceeba2f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -25,6 +25,9 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## Usage
|
27
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).
|
30
|
+
|
28
31
|
### Remove swear words 🤬
|
29
32
|
```
|
30
33
|
include PoliteText
|
@@ -47,16 +50,43 @@ PoliteText.is_polite?(str)
|
|
47
50
|
=> false
|
48
51
|
```
|
49
52
|
|
53
|
+
### Example for an Article model
|
54
|
+
|
55
|
+
```
|
56
|
+
# == Schema Information
|
57
|
+
#
|
58
|
+
# Table name: articles
|
59
|
+
#
|
60
|
+
# id :bigint not null, primary key
|
61
|
+
# text :string default(""), not null
|
62
|
+
# created_at :datetime not null
|
63
|
+
# updated_at :datetime not null
|
64
|
+
#
|
65
|
+
|
66
|
+
class Article < ApplicationRecord
|
67
|
+
include Politetext
|
68
|
+
|
69
|
+
# Callbacks
|
70
|
+
before_save :make_text_polite
|
71
|
+
|
72
|
+
# Methods
|
73
|
+
def make_text_polite
|
74
|
+
PoliteText.be_polite!(text)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
50
79
|
## Contributing
|
51
80
|
|
52
81
|
Bug reports and pull requests are welcome on GitHub at https://github.com/OpenGems/polite_text.
|
53
82
|
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
83
|
|
55
84
|
### Todo 💪
|
56
|
-
- [ ] Allow users to add their own swear words list
|
57
|
-
- [ ] Allow users to remove swear words from the default list
|
58
|
-
- [ ] Manage locales with I18N
|
59
|
-
- [ ] Add swear words from multiple languages
|
85
|
+
- [ ] Allow users to add their own swear words list.
|
86
|
+
- [ ] Allow users to remove swear words from the default list.
|
87
|
+
- [ ] Manage locales with I18N.
|
88
|
+
- [ ] Add swear words from multiple languages.
|
89
|
+
- [ ] Improve swear words list and keeping it short.
|
60
90
|
|
61
91
|
## License
|
62
92
|
|
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
data/lib/polite_text/base.rb
CHANGED
@@ -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
12
|
text.gsub!(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
|
@@ -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'
|