simple_blacklist 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 952c9eb375890475241b17c599065628d921cc4f
4
+ data.tar.gz: 771f98ef126b1f643196fc9427b19e95521facab
5
+ SHA512:
6
+ metadata.gz: 777e986e5e970bab4fa4bae4c73528c279a6bdc30f056d2ed5ad1427383631d51fbe311d8507669a2b526dfa39739d01f16dc0d7313a52ffb424322e7aa07bc8
7
+ data.tar.gz: 50d524c7ca9717a825104c4d78684ff8cbaa6454560a88c74306f6323b592b9766eb04bccc4b9e5a79ad6bc30b4f473551d7bd6cc3b4acb8d09117d8a3ce8a07
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_blacklist.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Washington Silva
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.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # SimpleBlacklist
2
+ ___
3
+
4
+ This project is designed to make easy the task of sanitizing string that contains words not allowed.
5
+
6
+ ## Installation
7
+ ___
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'simple_blacklist'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install simple_blacklist
22
+
23
+ ## Setup (Rails)
24
+ ___
25
+
26
+ $ simple_blacklist --configure
27
+
28
+ Will be created:
29
+
30
+ * *config/initializers/simple_blacklist.rb*
31
+ * *config/blacklist.yml*
32
+
33
+ ## Usage
34
+ ___
35
+
36
+ In your code, do:
37
+
38
+ ```ruby
39
+ offensive_text = "Kiss my ass"
40
+ SimpleBlacklist.sanitize(offensive_text)
41
+
42
+ # "Kiss my xxxxx"
43
+ ```
44
+
45
+ If configured *letters_variations* is also possible to sanitize texts written with special characters
46
+ ```ruby
47
+ offensive_text = "Kiss my @$$"
48
+ SimpleBlacklist.sanitize(offensive_text)
49
+
50
+ # "Kiss my xxxxx"
51
+ ```
52
+
53
+ ## Development
54
+ ___
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/simple_blacklist. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
63
+
64
+
65
+ ## License
66
+ ___
67
+
68
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
69
+
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simple_blacklist"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ require 'simple_blacklist/config'
4
+
5
+ base = BLACKLIST_BASE
6
+ config_dir = File.join(base, BLACKLIST_CONFIG['config_path'])
7
+ initializers_dir = File.join(config_dir, BLACKLIST_CONFIG['initializers_path'])
8
+ FileUtils.mkdir_p(config_dir) unless File.directory?(config_dir)
9
+ FileUtils.mkdir_p(initializers_dir) unless File.directory?(initializers_dir)
10
+ initializer_file = File.join(initializers_dir, 'simple_blacklist.rb')
11
+ blacklist_file = File.join(config_dir, 'blacklist.yml')
12
+
13
+ if ARGV.include? "--configure"
14
+ initializer_file_content = <<-FILE
15
+ # Define simple_blacklist file
16
+ SimpleBlacklist.set_blacklist_file(File.join(BLACKLIST_BASE, "config", "blacklist.yml"))
17
+
18
+ # Defines masks that will replace the words contained in the simple_blacklist
19
+ SimpleBlacklist.set_mask_to_denied_words("xxxxx")
20
+
21
+ # list of letters and characters that can replace the letters
22
+ SimpleBlacklist.set_letters_variations({
23
+ 'a' => ['@', '4', 'ª'],
24
+ 'e' => ['3', '&'],
25
+ 'i' => ['|', '1'],
26
+ 'o' => ['0', 'º'],
27
+ 's' => ['$', '5'],
28
+ 't' => ['7'],
29
+ 'g' => ['6'],
30
+ 'b' => ['6', '8']
31
+ })
32
+ FILE
33
+
34
+ blacklist_file_content = <<-FILE
35
+ ass
36
+ fuck
37
+ bitch
38
+ FILE
39
+
40
+ File.open(initializer_file, 'wb') {|f| f.write(initializer_file_content) } unless File.exist?(initializer_file)
41
+ File.open(blacklist_file, 'wb') {|f| f.write(blacklist_file_content) } unless File.exist?(blacklist_file)
42
+
43
+ puts " ༼ つ ◕_◕ ༽つ OK... Gem has been set!!! "
44
+ exit
45
+ end
46
+
47
+ unless File.exist?(initializer_file)
48
+ puts " ༼ つ ◕_◕ ༽つ OOOPS... Gem has not yet been set. To set run 'simple_blacklist --configure' "
49
+ exit
50
+ end
@@ -0,0 +1,5 @@
1
+ BLACKLIST_BASE = File.expand_path("")
2
+ BLACKLIST_CONFIG = {
3
+ "config_path" => 'config',
4
+ "initializers_path" => 'initializers',
5
+ }
@@ -0,0 +1,3 @@
1
+ module SimpleBlacklist
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,51 @@
1
+ require "simple_blacklist/config"
2
+ require "simple_blacklist/version"
3
+
4
+ module SimpleBlacklist
5
+ @@file ||= File.join(BLACKLIST_BASE, BLACKLIST_CONFIG['config_path'], 'blacklist.yml')
6
+ @@letters_variations ||= {}
7
+ @@blacklist ||= []
8
+ @@mask ||= "*****"
9
+
10
+ module_function
11
+ def set_blacklist_file(file)
12
+ @@file = file
13
+ end
14
+
15
+ def set_mask_to_denied_words(mask)
16
+ @@mask = mask
17
+ end
18
+
19
+ def set_letters_variations(list)
20
+ raise "Given object is not a hash" unless list.instance_of? Hash
21
+ @@letters_variations = list
22
+ end
23
+
24
+ def reload_blacklist
25
+ f = File.open(@@file, 'rb')
26
+ content = f.read
27
+ @@blacklist = content.split(/\W+/)
28
+ @@blacklist.map!(&:downcase)
29
+ end
30
+
31
+ def sanitize(text)
32
+ reload_blacklist
33
+ words = text.split(/[\s,.]/)
34
+ words.each do |word|
35
+ replaced = replace_letters(word)
36
+ text.gsub!(/(#{word})+/i, @@mask) if @@blacklist.include? replaced.downcase
37
+ end
38
+ text
39
+ end
40
+
41
+ def replace_letters(word)
42
+ replaced = word.clone
43
+ chars = word.split('')
44
+ chars.each do |char|
45
+ @@letters_variations.each do |(key,list_chars)|
46
+ replaced.gsub!(/(#{char})+/i, "#{key}") if list_chars.include? char.downcase
47
+ end
48
+ end
49
+ replaced
50
+ end
51
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_blacklist/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_blacklist"
8
+ spec.version = SimpleBlacklist::VERSION
9
+ spec.license = "MIT"
10
+ spec.platform = Gem::Platform::RUBY
11
+ spec.authors = ["Washington Silva"]
12
+ spec.email = ["w-osilva@hotmail.com"]
13
+ spec.homepage = ""
14
+ spec.rubyforge_project = "simple_blacklist"
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.test_files = `git ls-files -- {test,spec}/*`.split("\n")
17
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+ # spec.required_ruby_version = '>= 2.0.0'
20
+
21
+ spec.summary = %q{Simple Blacklist to sanitize strings}
22
+ spec.description = %q{This project is designed to make easy the task of sanitizing string that contains words not allowed. }
23
+
24
+ spec.add_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleBlacklist do
4
+ it 'has a version number' do
5
+ expect(SimpleBlacklist::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(true).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'simple_blacklist'
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_blacklist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Washington Silva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.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: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: 'This project is designed to make easy the task of sanitizing string
56
+ that contains words not allowed. '
57
+ email:
58
+ - w-osilva@hotmail.com
59
+ executables:
60
+ - console
61
+ - setup
62
+ - simple_blacklist
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - ".gitignore"
67
+ - ".rspec"
68
+ - ".travis.yml"
69
+ - CODE_OF_CONDUCT.md
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - bin/simple_blacklist
77
+ - lib/simple_blacklist.rb
78
+ - lib/simple_blacklist/config.rb
79
+ - lib/simple_blacklist/version.rb
80
+ - simple_blacklist.gemspec
81
+ - spec/simple_blacklist_spec.rb
82
+ - spec/spec_helper.rb
83
+ homepage: ''
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project: simple_blacklist
103
+ rubygems_version: 2.4.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Simple Blacklist to sanitize strings
107
+ test_files: []