polite_text 0.1.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b3eeefd6c47fe3bdc029ddfd592486673db2b55bcfff7405fc17e3a45c4c960
4
- data.tar.gz: 891412e5952963ea6109a9ac649b05b250bc0ae19035f5f80de10bb245f45a7d
3
+ metadata.gz: 574591328155e7985751a85bfdb2610376f9c976b4d0a589c1d735ec9bfb9816
4
+ data.tar.gz: b0f61d51a49c6882dbd666a495b20b2e0f12a5a2ae716c20350b2739e3910afe
5
5
  SHA512:
6
- metadata.gz: 3b87c8045b5f0cab33be0462390fac0d28c628ec3a28d9345748d620578930d83c21eeedb02fb7431a4049f835c18e9e8e397feccc247e0bcaff6606a0966ccb
7
- data.tar.gz: 3ce5f283f3b2775564581aeb7bde43c0b4995de59c9824838537facfef5348eee23068367fea1f6f8ba8d2a124473e43b00a2477e6532d6eade19749d3f3abc7
6
+ metadata.gz: d678889edb60886cfb83f6a186335e6371238cd45669eec435f1cf0f52f981cd074cfa04cbb8181243314edb68c371b0e9ca45805d9184719a1b8f1518839064
7
+ data.tar.gz: 705cbb3d6f397a4292aa858fc734d3dea33d7fa4c6989d4d848b3968948b2f9b57ca367c076a00968eafb9d931b58ab823b24e3c0b2421594ee4c5f13ceeba2f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polite_text (0.1.22)
4
+ polite_text (0.1.2)
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 based on a default swear words list or your own.
8
+ 👉 Replace the swear words or execute callbacks if the input is not polite.
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 with the default swear words list 🌝
26
+ ## Usage
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,6 +35,7 @@ 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
+
38
39
  => "This gem is a *** big *** but let's try it"
39
40
  ```
40
41
 
@@ -45,6 +46,7 @@ include PoliteText
45
46
  str = "This gem is a fucking big shit but let's try it"
46
47
 
47
48
  PoliteText.is_polite?(str)
49
+
48
50
  => false
49
51
  ```
50
52
 
@@ -62,7 +64,7 @@ PoliteText.is_polite?(str)
62
64
  #
63
65
 
64
66
  class Article < ApplicationRecord
65
- include PoliteText
67
+ include Politetext
66
68
 
67
69
  # Callbacks
68
70
  before_save :make_text_polite
@@ -74,53 +76,17 @@ class Article < ApplicationRecord
74
76
  end
75
77
  ```
76
78
 
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
-
115
79
  ## Contributing
116
80
 
117
81
  Bug reports and pull requests are welcome on GitHub at https://github.com/OpenGems/polite_text.
118
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.
119
83
 
120
84
  ### Todo 💪
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.
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.
124
90
 
125
91
  ## License
126
92
 
@@ -2,13 +2,16 @@ require 'yaml'
2
2
 
3
3
  module PoliteText
4
4
  class Base
5
- def swear_words(custom_swear_words_path)
6
- @swear_words ||= /\b(#{Regexp.union(swear_words_list(custom_swear_words_path)).source})\b/
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(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']
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']
12
15
  end
13
16
 
14
17
  private
@@ -17,9 +20,5 @@ module PoliteText
17
20
  def locale
18
21
  @locale ||= 'en'
19
22
  end
20
-
21
- def swear_words_load_path
22
- "#{__dir__}/../locales/#{locale}.yml"
23
- end
24
23
  end
25
24
  end
@@ -2,15 +2,14 @@ module PoliteText
2
2
  class TextCleaner < Base
3
3
  attr_reader :text
4
4
 
5
- def initialize(text, custom_swear_words_path = nil)
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(@custom_swear_words_path), '***') || text
12
+ text.gsub!(swear_words, '***')
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, custom_swear_words_path = nil)
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(@custom_swear_words_path))
12
+ !@text.match?(swear_words)
14
13
  end
15
14
  end
16
15
  end
@@ -1,3 +1,3 @@
1
1
  module PoliteText
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.21"
3
3
  end
data/lib/polite_text.rb CHANGED
@@ -4,12 +4,12 @@ require 'polite_text/text_cleaner'
4
4
 
5
5
  module PoliteText
6
6
  class << self
7
- def be_polite!(text, custom_swear_words_path = nil)
8
- PoliteText::TextCleaner.new(text, custom_swear_words_path).clean!
7
+ def be_polite!(text)
8
+ PoliteText::TextCleaner.new(text).clean!
9
9
  end
10
10
 
11
- def is_polite?(text, custom_swear_words_path = nil)
12
- PoliteText::TextScanner.new(text, custom_swear_words_path).match_swear_word?
11
+ def is_polite?(text)
12
+ PoliteText::TextScanner.new(text).match_swear_word?
13
13
  end
14
14
  end
15
15
  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.3
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - DumasOlivier