polite_text 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cbfcbe17185f2648936f26afaca7ddacaba70a9901f882c2a517e4baa96f2818
4
+ data.tar.gz: 9bbfdbc8729c77a9d008a6a70836785ea467def92219a204e72472a8973373f4
5
+ SHA512:
6
+ metadata.gz: 2f3d14c0213deac733467cf9f920ac03246453a88f04703db4c2fd3244e0fe1e6564366c62411d8a000dcf9df355b72717c09db24396ff5c4d6b7f877996096e
7
+ data.tar.gz: 6a2db207e7522e085a77342abe9019b3334462982be396c57fa1ab19e2c9f97e1878bdb51b3f8873c0dc36badb5c336108ffeeb45d3cd180c0213b020fb5445f
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in polite_text.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 DumasOlivier
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # PoliteText
2
+
3
+ PoliteText is making your users' input polite 👀
4
+
5
+ 👉 Replace the swear words or execute callbacks if the input is not polite.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'polite_text'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install polite_text
22
+
23
+ ## Usage
24
+
25
+ ### Remove swear words 🤬
26
+ ```
27
+ include PoliteText
28
+
29
+ str = "This gem is a fucking big shit but let's try it"
30
+
31
+ PoliteText.be_polite!(str)
32
+
33
+ => "This gem is a *** big *** but let's try it"
34
+ ```
35
+
36
+ ### Check if string is polite 🙅‍♂️ 🙅‍♀️
37
+ ```
38
+ include PoliteText
39
+
40
+ str = "This gem is a fucking big shit but let's try it"
41
+
42
+ PoliteText.is_polite?(str)
43
+
44
+ => false
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/OpenGems/polite_text.
50
+ 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
+
52
+ ### 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
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "polite_text"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ # Don t show this to your mom.
2
+
3
+ swear_words:
4
+ - fuck
5
+ - fuckyou
6
+ - fucker
7
+ - fucking
8
+ - dick head
9
+ - dick
10
+ - dickhole
11
+ - cock
12
+ - asshole
13
+ - son of a bitch
14
+ - bitch
15
+ - biatch
16
+ - whore
17
+ - bastard
18
+ - wanker
19
+ - shit
20
+ - piss
21
+ - pussy
@@ -0,0 +1,18 @@
1
+ require 'polite_text/base'
2
+ require 'polite_text/swear_words_scanner'
3
+ require 'polite_text/swear_words_cleaner'
4
+
5
+ module PoliteText
6
+ class Error < StandardError; end
7
+
8
+ 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
12
+ end
13
+
14
+ def is_polite?(text)
15
+ PoliteText::SwearWordsScanner.new(text).match_swear_word?
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ module PoliteText
2
+ 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"
9
+ end
10
+
11
+ def swear_words_list
12
+ YAML.load_file(swear_words_load_path)['swear_words']
13
+ end
14
+
15
+ private
16
+
17
+ # Todo: Implement dynamic locale with I18N
18
+ def locale
19
+ @locale ||= 'en'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,3 @@
1
+ module PoliteText
2
+ VERSION = "0.1.1"
3
+ end
Binary file
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/polite_text/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'polite_text'
5
+ spec.version = PoliteText::VERSION
6
+ spec.authors = ['DumasOlivier']
7
+ spec.email = ['dumas.olivier@outlook.fr']
8
+
9
+ spec.summary = 'PoliteText is making your users\' input polite.'
10
+ spec.description = 'Replace swear words from users\' inputs or be notified and execute your own callbacks.'
11
+ spec.homepage = 'https://github.com/OpenGems/polite_text'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
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
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
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'
31
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polite_text
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - DumasOlivier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Replace swear words from users' inputs or be notified and execute your
14
+ own callbacks.
15
+ email:
16
+ - dumas.olivier@outlook.fr
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".travis.yml"
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - lib/locales/en.yml
31
+ - lib/polite_text.rb
32
+ - lib/polite_text/base.rb
33
+ - lib/polite_text/swear_words_cleaner.rb
34
+ - lib/polite_text/swear_words_scanner.rb
35
+ - lib/polite_text/version.rb
36
+ - polite_text-0.1.0.gem
37
+ - polite_text.gemspec
38
+ homepage: https://github.com/OpenGems/polite_text
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ homepage_uri: https://github.com/OpenGems/polite_text
43
+ source_code_uri: https://github.com/OpenGems/polite_text
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.1.4
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: PoliteText is making your users' input polite.
63
+ test_files: []