polite_text 0.1.1 → 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: cbfcbe17185f2648936f26afaca7ddacaba70a9901f882c2a517e4baa96f2818
4
- data.tar.gz: 9bbfdbc8729c77a9d008a6a70836785ea467def92219a204e72472a8973373f4
3
+ metadata.gz: b61709fd69469a4a019e0a041b18c95700d72132992293b2e2f49eebe9df6662
4
+ data.tar.gz: d243724fa7ef4eb931e4b6e295b6b1d8afec2a81c82d399e5759f764f808c1e4
5
5
  SHA512:
6
- metadata.gz: 2f3d14c0213deac733467cf9f920ac03246453a88f04703db4c2fd3244e0fe1e6564366c62411d8a000dcf9df355b72717c09db24396ff5c4d6b7f877996096e
7
- data.tar.gz: 6a2db207e7522e085a77342abe9019b3334462982be396c57fa1ab19e2c9f97e1878bdb51b3f8873c0dc36badb5c336108ffeeb45d3cd180c0213b020fb5445f
6
+ metadata.gz: 1a4fbc965f3c668bedbe5e0bf1df64f72077199c743938ec009c82a71e6c889f11492c92d18c58776303e31d34acbacdd01ea6dc47666731a41ade9abb044255
7
+ data.tar.gz: c232a79a3dd3c5bd8ea7abfbfbe99f807de817143d54a57db31e1feb85a88ec5e6c75c3f040a3c05f14f89401b265b00f1e3c1b47a7daaad0dbf9e1a72c64613
data/.gitignore CHANGED
@@ -9,3 +9,12 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ # IDE
14
+ /.idea
15
+ .idea/workspace.xml
16
+ .rakeTasks
17
+ .generators
18
+
19
+ # Gem
20
+ *.gem
data/Gemfile CHANGED
@@ -2,6 +2,3 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in polite_text.gemspec
4
4
  gemspec
5
-
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ polite_text (0.1.22)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ concurrent-ruby (1.1.7)
10
+ diff-lcs (1.4.4)
11
+ docile (1.3.2)
12
+ faker (2.14.0)
13
+ i18n (>= 1.6, < 2)
14
+ i18n (1.8.5)
15
+ concurrent-ruby (~> 1.0)
16
+ rake (13.0.1)
17
+ rspec (3.10.0)
18
+ rspec-core (~> 3.10.0)
19
+ rspec-expectations (~> 3.10.0)
20
+ rspec-mocks (~> 3.10.0)
21
+ rspec-core (3.10.0)
22
+ rspec-support (~> 3.10.0)
23
+ rspec-expectations (3.10.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.10.0)
26
+ rspec-mocks (3.10.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-support (3.10.0)
30
+ simplecov (0.19.1)
31
+ docile (~> 1.1)
32
+ simplecov-html (~> 0.11)
33
+ simplecov-html (0.12.3)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ faker (~> 2.14)
40
+ polite_text!
41
+ rake (~> 13.0, >= 13.0.1)
42
+ rspec (~> 3.10)
43
+ simplecov (~> 0.19.1)
44
+
45
+ BUNDLED WITH
46
+ 2.1.4
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # PoliteText
2
+ [![Gem Version](https://badge.fury.io/rb/polite_text.svg)](https://badge.fury.io/rb/polite_text)
3
+ [![security](https://hakiri.io/github/OpenGems/polite_text/master.svg)](https://hakiri.io/github/OpenGems/polite_text/master)
4
+ ![Gem](https://img.shields.io/gem/dt/polite_text)
2
5
 
3
6
  PoliteText is making your users' input polite 👀
4
7
 
5
- 👉 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.
6
9
 
7
- ## Installation
10
+ ## Installation 👨‍💻 👩‍💻
8
11
 
9
12
  Add this line to your application's Gemfile:
10
13
 
@@ -20,7 +23,10 @@ Or install it yourself as:
20
23
 
21
24
  $ gem install polite_text
22
25
 
23
- ## 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).
24
30
 
25
31
  ### Remove swear words 🤬
26
32
  ```
@@ -29,7 +35,6 @@ include PoliteText
29
35
  str = "This gem is a fucking big shit but let's try it"
30
36
 
31
37
  PoliteText.be_polite!(str)
32
-
33
38
  => "This gem is a *** big *** but let's try it"
34
39
  ```
35
40
 
@@ -40,21 +45,82 @@ include PoliteText
40
45
  str = "This gem is a fucking big shit but let's try it"
41
46
 
42
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
+ # my_custom_swear_words.yml
83
+
84
+ swear_words:
85
+ - gem
86
+ - big
87
+ - but
88
+ ```
43
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)
44
111
  => false
45
112
  ```
46
113
 
114
+
47
115
  ## Contributing
48
116
 
49
117
  Bug reports and pull requests are welcome on GitHub at https://github.com/OpenGems/polite_text.
50
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.
51
119
 
52
120
  ### Todo 💪
53
- - [ ] Testing
54
- - [ ] Allow users to add their own swear words list
55
- - [ ] Allow users to remove swear words from the default list
56
- - [ ] Manage locales with I18N
57
- - [ ] Add swear words from multiple languages
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.
58
124
 
59
125
  ## License
60
126
 
@@ -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
@@ -1,18 +1,15 @@
1
1
  require 'polite_text/base'
2
- require 'polite_text/swear_words_scanner'
3
- require 'polite_text/swear_words_cleaner'
2
+ require 'polite_text/text_scanner'
3
+ require 'polite_text/text_cleaner'
4
4
 
5
5
  module PoliteText
6
- class Error < StandardError; end
7
-
8
6
  class << self
9
- # Replace swear words in a text. Can provide optional arg to replace by something.
10
- def be_polite!(text)
11
- PoliteText::SwearWordsCleaner.new(text).clean
7
+ def be_polite!(text, custom_swear_words_path = nil)
8
+ PoliteText::TextCleaner.new(text, custom_swear_words_path).clean!
12
9
  end
13
10
 
14
- def is_polite?(text)
15
- PoliteText::SwearWordsScanner.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?
16
13
  end
17
14
  end
18
15
  end
@@ -1,22 +1,25 @@
1
+ require 'yaml'
2
+
1
3
  module PoliteText
2
4
  class Base
3
- def swear_words
4
- @swear_words ||= /\b(#{Regexp.union(swear_words_list).source})\b/
5
- end
6
-
7
- def swear_words_load_path
8
- "#{__dir__}/../locales/#{locale}.yml"
5
+ def swear_words(custom_swear_words_path)
6
+ @swear_words ||= /\b(#{Regexp.union(swear_words_list(custom_swear_words_path)).source})\b/
9
7
  end
10
8
 
11
- def swear_words_list
12
- 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']
13
12
  end
14
13
 
15
14
  private
16
15
 
17
- # Todo: Implement dynamic locale with I18N
16
+ # TODO: Implement dynamic locale with I18N
18
17
  def locale
19
18
  @locale ||= 'en'
20
19
  end
20
+
21
+ def swear_words_load_path
22
+ "#{__dir__}/../locales/#{locale}.yml"
23
+ end
21
24
  end
22
25
  end
@@ -0,0 +1,16 @@
1
+ module PoliteText
2
+ class TextCleaner < Base
3
+ attr_reader :text
4
+
5
+ def initialize(text, custom_swear_words_path = nil)
6
+ raise ArgumentError.new('The text can not be nil') if text.nil?
7
+
8
+ @text = text.to_s
9
+ @custom_swear_words_path = custom_swear_words_path
10
+ end
11
+
12
+ def clean!
13
+ text.gsub!(swear_words(@custom_swear_words_path), '***') || text
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module PoliteText
2
+ class TextScanner < Base
3
+ attr_reader :text
4
+
5
+ def initialize(text, custom_swear_words_path = nil)
6
+ raise ArgumentError.new('The text can not be nil') if text.nil?
7
+
8
+ @text = text.to_s
9
+ @custom_swear_words_path = custom_swear_words_path
10
+ end
11
+
12
+ def match_swear_word?
13
+ !@text.match?(swear_words(@custom_swear_words_path))
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module PoliteText
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -17,15 +17,16 @@ 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('..', __FILE__)) do
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'
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ['lib']
26
26
 
27
- # TODO: Add testing
28
- #spec.add_development_dependency 'coveralls', '~> 0.8'
29
- #spec.add_development_dependency 'rspec-rails', '~> 4.0.0'
30
- #spec.add_development_dependency 'simplecov', '~> 0.16'
27
+ # TODO: Add testing + coverage
28
+ spec.add_development_dependency 'rspec', '~> 3.10'
29
+ spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
30
+ spec.add_development_dependency 'simplecov', '~> 0.19.1'
31
+ spec.add_development_dependency 'faker', '~> 2.14'
31
32
  end
metadata CHANGED
@@ -1,15 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polite_text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.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-04 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2020-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 13.0.1
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '13.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 13.0.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.19.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.19.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: faker
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.14'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.14'
13
75
  description: Replace swear words from users' inputs or be notified and execute your
14
76
  own callbacks.
15
77
  email:
@@ -22,6 +84,7 @@ files:
22
84
  - ".rspec"
23
85
  - ".travis.yml"
24
86
  - Gemfile
87
+ - Gemfile.lock
25
88
  - LICENSE.txt
26
89
  - README.md
27
90
  - Rakefile
@@ -30,10 +93,9 @@ files:
30
93
  - lib/locales/en.yml
31
94
  - lib/polite_text.rb
32
95
  - lib/polite_text/base.rb
33
- - lib/polite_text/swear_words_cleaner.rb
34
- - lib/polite_text/swear_words_scanner.rb
96
+ - lib/polite_text/text_cleaner.rb
97
+ - lib/polite_text/text_scanner.rb
35
98
  - lib/polite_text/version.rb
36
- - polite_text-0.1.0.gem
37
99
  - polite_text.gemspec
38
100
  homepage: https://github.com/OpenGems/polite_text
39
101
  licenses:
@@ -1,15 +0,0 @@
1
- module PoliteText
2
- class SwearWordsCleaner < Base
3
- attr_reader :text
4
-
5
- def initialize(text)
6
- return '' if text.nil? || text.empty?
7
-
8
- @text = text
9
- end
10
-
11
- def clean
12
- text.gsub!(swear_words, '***')
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module PoliteText
2
- class SwearWordsScanner < Base
3
- attr_reader :text
4
-
5
- def initialize(text)
6
- return false if text.nil? || text.empty?
7
-
8
- @text = text
9
- end
10
-
11
- def match_swear_word?
12
- !@text.match?(swear_words)
13
- end
14
- end
15
- end
Binary file