sauber 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ea0fbe8bfe03290d7721365566c45b9f3ed8fc4
4
+ data.tar.gz: 609a9e52c7369f193185659a64325fc9b55a2fea
5
+ SHA512:
6
+ metadata.gz: 04d2e49917b4f7d3bb4193133ef6d7e47959aa7cfc8d05b63852548d971b6d45902e443a366c5507de3b4ab9177d7814fd4707e7a91b67d563a3a23c30028923
7
+ data.tar.gz: 4beb4c34a586fa0cbdf04fc970dde6d106c71abab559d38da214501e37180b65b551c3ab89b2455d9a4cec3bd4aed55cd6956a90c1aec8692381395e7d1730c1
@@ -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
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install:
5
+ - gem install bundler
6
+ install:
7
+ - bundle install
8
+ addons:
9
+ code_climate:
10
+ repo_token: 6523a3eb32ccb84a0308d6308e038ce33c75e556fcb24dbf759dc8caad5d9d78
11
+ notifications:
12
+ email:
13
+ recipients:
14
+ - icaro.seara@email.com
15
+ on_failure: change
16
+ on_success: never
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sauber.gemspec
4
+ gemspec
5
+ gem "codeclimate-test-reporter", group: :test, require: nil
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Icaro Seara
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,72 @@
1
+ # Sauber
2
+
3
+ A tiny profanity filter.
4
+
5
+ [![Build Status](https://travis-ci.org/icaroseara/sauber.svg)](https://travis-ci.org/icaroseara/sauber) [![Code Climate](https://codeclimate.com/github/icaroseara/sauber/badges/gpa.svg)](https://codeclimate.com/github/icaroseara/sauber) [![Test Coverage](https://codeclimate.com/github/icaroseara/sauber/badges/coverage.svg)](https://codeclimate.com/github/icaroseara/sauber)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sauber'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sauber
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ Sauber.configure do |config|
27
+ config.blacklist = ["bad", "crime", "war"]
28
+ config.whitelist = ["peace"]
29
+ config.replacement = :stars
30
+ end
31
+ ```
32
+
33
+ ### Blacklist
34
+
35
+ Words or phrases that you would like to remove.
36
+
37
+ `config.whitelist` accepts the following values:
38
+
39
+ - An array with words
40
+ - A string representing a path to a yml file
41
+
42
+ ### Whitelist
43
+
44
+ Phrases that contain a word from the blacklist that you don't wish to remove.
45
+
46
+ `config.blacklist` accepts the following values:
47
+
48
+ - An array with words
49
+ - A string representing a path to a yml file
50
+
51
+ ### Replacement
52
+
53
+ `config.replacement` accepts the following values:
54
+ - :stars : Replaces profane words with '*' up to the word's length
55
+
56
+ ### Basic Usage
57
+
58
+ ```ruby
59
+ Sauber.clean("simple text")
60
+ => "simple text"
61
+
62
+ Sauber.clean("text with shit")
63
+ => "text with ****"
64
+ ```
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it ( https://github.com/[my-github-username]/sauber/fork )
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create a new Pull Request
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+ rescue LoadError
9
+ # no rspec available
10
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sauber"
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
@@ -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,14 @@
1
+ require "sauber/version"
2
+ require 'sauber/base'
3
+
4
+ module Sauber extend self
5
+ attr_accessor :whitelist, :blacklist, :replacement
6
+
7
+ def configure
8
+ yield self
9
+ end
10
+
11
+ def clean text
12
+ Sauber::Base.clean text
13
+ end
14
+ end
@@ -0,0 +1,53 @@
1
+ module Sauber
2
+ class Base
3
+ class << self
4
+ def clean text
5
+ return text if text.empty?
6
+ text.split(/(\s)/).collect{ |w| clean_word(w) }.join
7
+ end
8
+
9
+ private
10
+
11
+ def blacklist
12
+ @blacklist ||= get_content Sauber.blacklist
13
+ end
14
+
15
+ def whitelist
16
+ @whitelist ||= get_content Sauber.whitelist
17
+ end
18
+
19
+ def invalid? word
20
+ blacklist.include?(word.downcase) && !whitelist.include?(word.downcase)
21
+ end
22
+
23
+ def replace word
24
+ case Sauber.replacement
25
+ when :stars
26
+ '*' * word.length
27
+ else
28
+ word
29
+ end
30
+ end
31
+
32
+ def clean_word word
33
+ return word unless word.strip.size > 2
34
+
35
+ if word.index(/[\W]/)
36
+ word = word.split(/(\W)/).collect{ |w| clean_word(w) }.join
37
+ subword = word.gsub(/\W/, '')
38
+ word = subword if invalid?(subword)
39
+ end
40
+
41
+ invalid?(word) ? replace(word) : word
42
+ end
43
+
44
+ def get_content list
45
+ case list
46
+ when Array then list
47
+ when String, Pathname then YAML.load_file( list.to_s )
48
+ else []
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module Sauber
2
+ VERSION = "0.1.0"
3
+ 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 'sauber/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sauber"
8
+ spec.version = Sauber::VERSION
9
+ spec.authors = ["Icaro Seara"]
10
+ spec.email = ["icaro.seara@gmail.com"]
11
+ spec.homepage = 'https://github.com/icaroseara/sauber'
12
+ spec.summary = 'A tiny profanity filter.'
13
+ spec.description = 'A tiny profanity filter that use blacklist, whitelist and sanitization rules to clean up profanity in text.'
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.9"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "rspec-nc"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "pry-remote"
26
+ spec.add_development_dependency "pry-nav"
27
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sauber
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Icaro Seara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-05 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-nc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-remote
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A tiny profanity filter that use blacklist, whitelist and sanitization
112
+ rules to clean up profanity in text.
113
+ email:
114
+ - icaro.seara@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/sauber.rb
129
+ - lib/sauber/base.rb
130
+ - lib/sauber/version.rb
131
+ - sauber.gemspec
132
+ homepage: https://github.com/icaroseara/sauber
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.2.2
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: A tiny profanity filter.
156
+ test_files: []