polite_text 0.1.22 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '00696f507481712af5a77b82abc07cc702964927fff97aa3b05babe07ba0c446'
4
- data.tar.gz: 4c1b77cafdfac87010951bce6ea7adac6813657d9f704c40022e61befdf3479b
3
+ metadata.gz: b61709fd69469a4a019e0a041b18c95700d72132992293b2e2f49eebe9df6662
4
+ data.tar.gz: d243724fa7ef4eb931e4b6e295b6b1d8afec2a81c82d399e5759f764f808c1e4
5
5
  SHA512:
6
- metadata.gz: c4d9788bfe42ea5196f6e3c5261df476fe8644366e4fa19d96f34370974ed35bf99142af85a51fdef1bca9631c0924e5778d5149b951bb6200ad04998fdd1c3d
7
- data.tar.gz: cf7e94f809f18d5b43ccb0df506d5bfa140d54d2dbded21d907196e780faa7d560d82fa6cefc5a00465e3e7a7029b62cbbfb0ce15e632c449faf29800d4fcc16
6
+ metadata.gz: 1a4fbc965f3c668bedbe5e0bf1df64f72077199c743938ec009c82a71e6c889f11492c92d18c58776303e31d34acbacdd01ea6dc47666731a41ade9abb044255
7
+ data.tar.gz: c232a79a3dd3c5bd8ea7abfbfbe99f807de817143d54a57db31e1feb85a88ec5e6c75c3f040a3c05f14f89401b265b00f1e3c1b47a7daaad0dbf9e1a72c64613
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polite_text (0.1.21)
4
+ polite_text (0.1.22)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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,7 @@ 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
27
 
28
28
  ### Swear words 🔞
29
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).
@@ -35,7 +35,6 @@ include PoliteText
35
35
  str = "This gem is a fucking big shit but let's try it"
36
36
 
37
37
  PoliteText.be_polite!(str)
38
-
39
38
  => "This gem is a *** big *** but let's try it"
40
39
  ```
41
40
 
@@ -46,7 +45,6 @@ include PoliteText
46
45
  str = "This gem is a fucking big shit but let's try it"
47
46
 
48
47
  PoliteText.is_polite?(str)
49
-
50
48
  => false
51
49
  ```
52
50
 
@@ -76,17 +74,53 @@ class Article < ApplicationRecord
76
74
  end
77
75
  ```
78
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
+ # my_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`
91
+
92
+ 👉 You just need to pass the path to this file as a second argument.
93
+
94
+ ### Example for an Article model
95
+
96
+ ### Remove or detect swear words 🤬 🙅‍♂️ 🙅‍♀️
97
+ ```
98
+ # Inside a random_model.rb
99
+
100
+ include PoliteText
101
+
102
+ str = "This gem is a fucking big shit but let's try it"
103
+
104
+ current_dir = __dir__
105
+ custom_path = "#{current_dir}/../lib/polite_text/fr.yml"
106
+
107
+ PoliteText.be_polite!(str, custom_path)
108
+ => "This *** is a fucking *** shit *** let's try it"
109
+
110
+ PoliteText.is_polite?(str, custom_path)
111
+ => false
112
+ ```
113
+
114
+
79
115
  ## Contributing
80
116
 
81
117
  Bug reports and pull requests are welcome on GitHub at https://github.com/OpenGems/polite_text.
82
118
  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.
83
119
 
84
120
  ### Todo 💪
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.
121
+ - [ ] Manage locales with I18N for default swear words lists by country.
122
+ - [ ] Add default swear words lists from multiple languages.
123
+ - [ ] Improve the default swear words list and keeping it short.
90
124
 
91
125
  ## License
92
126
 
@@ -4,12 +4,12 @@ require 'polite_text/text_cleaner'
4
4
 
5
5
  module PoliteText
6
6
  class << self
7
- def be_polite!(text)
8
- PoliteText::TextCleaner.new(text).clean!
7
+ def be_polite!(text, custom_swear_words_path = nil)
8
+ PoliteText::TextCleaner.new(text, custom_swear_words_path).clean!
9
9
  end
10
10
 
11
- def is_polite?(text)
12
- PoliteText::TextScanner.new(text).match_swear_word?
11
+ def is_polite?(text, custom_swear_words_path = nil)
12
+ PoliteText::TextScanner.new(text, custom_swear_words_path).match_swear_word?
13
13
  end
14
14
  end
15
15
  end
@@ -2,16 +2,13 @@ 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).source})\b/
5
+ def swear_words(custom_swear_words_path)
6
+ @swear_words ||= /\b(#{Regexp.union(swear_words_list(custom_swear_words_path)).source})\b/
7
7
  end
8
8
 
9
- def swear_words_load_path
10
- "#{__dir__}/../locales/#{locale}.yml"
11
- end
12
-
13
- def swear_words_list
14
- YAML.load_file(swear_words_load_path)['swear_words']
9
+ def swear_words_list(custom_swear_words_path = nil)
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
@@ -20,5 +17,9 @@ module PoliteText
20
17
  def locale
21
18
  @locale ||= 'en'
22
19
  end
20
+
21
+ def swear_words_load_path
22
+ "#{__dir__}/../locales/#{locale}.yml"
23
+ end
23
24
  end
24
25
  end
@@ -2,14 +2,15 @@ module PoliteText
2
2
  class TextCleaner < Base
3
3
  attr_reader :text
4
4
 
5
- def initialize(text)
5
+ def initialize(text, custom_swear_words_path = nil)
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
9
10
  end
10
11
 
11
12
  def clean!
12
- text.gsub!(swear_words, '***') || text
13
+ text.gsub!(swear_words(@custom_swear_words_path), '***') || text
13
14
  end
14
15
  end
15
16
  end
@@ -2,14 +2,15 @@ module PoliteText
2
2
  class TextScanner < Base
3
3
  attr_reader :text
4
4
 
5
- def initialize(text)
5
+ def initialize(text, custom_swear_words_path = nil)
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
9
10
  end
10
11
 
11
12
  def match_swear_word?
12
- !@text.match?(swear_words)
13
+ !@text.match?(swear_words(@custom_swear_words_path))
13
14
  end
14
15
  end
15
16
  end
@@ -1,3 +1,3 @@
1
1
  module PoliteText
2
- VERSION = "0.1.22"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polite_text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DumasOlivier