profanity_filter 0.0.2 → 0.1.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.
- data/README.rdoc +1 -0
 - data/VERSION +1 -1
 - data/lib/profanity_filter.rb +13 -13
 - data/profanity_filter.gemspec +6 -15
 - metadata +23 -48
 
    
        data/README.rdoc
    CHANGED
    
    | 
         @@ -78,6 +78,7 @@ You can run the benchmarks via: 
     | 
|
| 
       78 
78 
     | 
    
         
             
            * Clean up dictionary implementation and substitution (suboptimal and messy)
         
     | 
| 
       79 
79 
     | 
    
         
             
            * Move benchmarks into a rake task
         
     | 
| 
       80 
80 
     | 
    
         
             
            * Build out rdocs
         
     | 
| 
      
 81 
     | 
    
         
            +
            * Ability to supplement the profanity database (with a yaml outside of the gem) via @seankibler
         
     | 
| 
       81 
82 
     | 
    
         | 
| 
       82 
83 
     | 
    
         
             
            == License
         
     | 
| 
       83 
84 
     | 
    
         | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.0 
     | 
| 
      
 1 
     | 
    
         
            +
            0.1.0
         
     | 
    
        data/lib/profanity_filter.rb
    CHANGED
    
    | 
         @@ -4,7 +4,7 @@ module ProfanityFilter 
     | 
|
| 
       4 
4 
     | 
    
         
             
                  base.class_eval do
         
     | 
| 
       5 
5 
     | 
    
         
             
                    extend ClassMethods
         
     | 
| 
       6 
6 
     | 
    
         
             
                  end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       8 
8 
     | 
    
         
             
              end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              module ClassMethods
         
     | 
| 
         @@ -12,26 +12,26 @@ module ProfanityFilter 
     | 
|
| 
       12 
12 
     | 
    
         
             
                  option = attr_names.pop[:method] if attr_names.last.is_a?(Hash)
         
     | 
| 
       13 
13 
     | 
    
         
             
                  attr_names.each { |attr_name| setup_callbacks_for(attr_name, option) }
         
     | 
| 
       14 
14 
     | 
    
         
             
                end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       16 
16 
     | 
    
         
             
                def profanity_filter(*attr_names)
         
     | 
| 
       17 
17 
     | 
    
         
             
                  option = attr_names.pop[:method] if attr_names.last.is_a?(Hash)
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                  attr_names.each do |attr_name| 
     | 
| 
      
 19 
     | 
    
         
            +
                  attr_names.each do |attr_name|
         
     | 
| 
       20 
20 
     | 
    
         
             
                    instance_eval do
         
     | 
| 
       21 
     | 
    
         
            -
                      define_method "#{attr_name}_clean" do; ProfanityFilter::Base.clean(self[attr_name.to_sym], option); end 
     | 
| 
      
 21 
     | 
    
         
            +
                      define_method "#{attr_name}_clean" do; ProfanityFilter::Base.clean(self[attr_name.to_sym], option); end
         
     | 
| 
       22 
22 
     | 
    
         
             
                      define_method "#{attr_name}_original"do; self[attr_name]; end
         
     | 
| 
       23 
23 
     | 
    
         
             
                      alias_method attr_name.to_sym, "#{attr_name}_clean".to_sym
         
     | 
| 
       24 
24 
     | 
    
         
             
                    end
         
     | 
| 
       25 
25 
     | 
    
         
             
                  end
         
     | 
| 
       26 
26 
     | 
    
         
             
                end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       28 
28 
     | 
    
         
             
                def setup_callbacks_for(attr_name, option)
         
     | 
| 
       29 
29 
     | 
    
         
             
                  before_validation do |record|
         
     | 
| 
       30 
30 
     | 
    
         
             
                    record[attr_name.to_sym] = ProfanityFilter::Base.clean(record[attr_name.to_sym], option)
         
     | 
| 
       31 
31 
     | 
    
         
             
                  end
         
     | 
| 
       32 
32 
     | 
    
         
             
                end
         
     | 
| 
       33 
33 
     | 
    
         
             
              end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       35 
35 
     | 
    
         
             
              class Base
         
     | 
| 
       36 
36 
     | 
    
         
             
                cattr_accessor :replacement_text, :dictionary_file, :dictionary
         
     | 
| 
       37 
37 
     | 
    
         
             
                @@replacement_text = '@#$%'
         
     | 
| 
         @@ -46,25 +46,25 @@ module ProfanityFilter 
     | 
|
| 
       46 
46 
     | 
    
         
             
                  def profane?(text = '')
         
     | 
| 
       47 
47 
     | 
    
         
             
                    text == clean(text) ? false : true
         
     | 
| 
       48 
48 
     | 
    
         
             
                  end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
       50 
50 
     | 
    
         
             
                  def clean(text, replace_method = '')
         
     | 
| 
       51 
51 
     | 
    
         
             
                    return text if text.blank?
         
     | 
| 
       52 
52 
     | 
    
         
             
                    @replace_method = replace_method
         
     | 
| 
       53 
53 
     | 
    
         
             
                    text.split(/(\s)/).collect{ |word| clean_word(word) }.join
         
     | 
| 
       54 
54 
     | 
    
         
             
                  end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
       56 
56 
     | 
    
         
             
                  def clean_word(word)
         
     | 
| 
       57 
57 
     | 
    
         
             
                     return word unless(word.strip.size > 2)
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
       59 
59 
     | 
    
         
             
                     if word.index(/[\W]/)
         
     | 
| 
       60 
60 
     | 
    
         
             
                       word = word.split(/(\W)/).collect{ |subword| clean_word(subword) }.join
         
     | 
| 
       61 
61 
     | 
    
         
             
                       concat = word.gsub(/\W/, '')
         
     | 
| 
       62 
62 
     | 
    
         
             
                       word = concat if banned? concat
         
     | 
| 
       63 
63 
     | 
    
         
             
                     end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
       65 
65 
     | 
    
         
             
                     banned?(word) ? replacement(word) : word
         
     | 
| 
       66 
66 
     | 
    
         
             
                   end
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
       68 
68 
     | 
    
         
             
                   def replacement(word)
         
     | 
| 
       69 
69 
     | 
    
         
             
                     case @replace_method
         
     | 
| 
       70 
70 
     | 
    
         
             
                     when 'dictionary'
         
     | 
| 
         @@ -75,7 +75,7 @@ module ProfanityFilter 
     | 
|
| 
       75 
75 
     | 
    
         
             
                       word[1..word.size-2] = '*' * (word.size-2) if word.size > 2
         
     | 
| 
       76 
76 
     | 
    
         
             
                       word
         
     | 
| 
       77 
77 
     | 
    
         
             
                     when 'stars'
         
     | 
| 
       78 
     | 
    
         
            -
                       word = '*' * (word.size) 
     | 
| 
      
 78 
     | 
    
         
            +
                       word = '*' * (word.size)
         
     | 
| 
       79 
79 
     | 
    
         
             
                     else
         
     | 
| 
       80 
80 
     | 
    
         
             
                       replacement_text
         
     | 
| 
       81 
81 
     | 
    
         
             
                     end
         
     | 
| 
         @@ -84,4 +84,4 @@ module ProfanityFilter 
     | 
|
| 
       84 
84 
     | 
    
         
             
              end
         
     | 
| 
       85 
85 
     | 
    
         
             
            end
         
     | 
| 
       86 
86 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
            ActiveRecord::Base.send(:include, ProfanityFilter)
         
     | 
| 
      
 87 
     | 
    
         
            +
            ActiveRecord::Base.send(:include, ProfanityFilter) if defined?(ActiveRecord)
         
     | 
    
        data/profanity_filter.gemspec
    CHANGED
    
    | 
         @@ -5,11 +5,11 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = %q{profanity_filter}
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0.0 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.1.0"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
     | 
    
         
            -
              s.authors = [ 
     | 
| 
       12 
     | 
    
         
            -
              s.date = %q{2011- 
     | 
| 
      
 11 
     | 
    
         
            +
              s.authors = [%q{Adam Bair}]
         
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = %q{2011-09-30}
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.description = %q{Allows you to filter profanity using basic replacement or a dictionary term.}
         
     | 
| 
       14 
14 
     | 
    
         
             
              s.email = %q{adambair@gmail.com}
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.extra_rdoc_files = [
         
     | 
| 
         @@ -44,19 +44,10 @@ Gem::Specification.new do |s| 
     | 
|
| 
       44 
44 
     | 
    
         
             
                "test/test_harness.rb"
         
     | 
| 
       45 
45 
     | 
    
         
             
              ]
         
     | 
| 
       46 
46 
     | 
    
         
             
              s.homepage = %q{http://github.com/intridea/profanity_filter}
         
     | 
| 
       47 
     | 
    
         
            -
              s.licenses = [ 
     | 
| 
       48 
     | 
    
         
            -
              s.require_paths = [ 
     | 
| 
       49 
     | 
    
         
            -
              s.rubygems_version = %q{1. 
     | 
| 
      
 47 
     | 
    
         
            +
              s.licenses = [%q{MIT}]
         
     | 
| 
      
 48 
     | 
    
         
            +
              s.require_paths = [%q{lib}]
         
     | 
| 
      
 49 
     | 
    
         
            +
              s.rubygems_version = %q{1.8.8}
         
     | 
| 
       50 
50 
     | 
    
         
             
              s.summary = %q{A Rails plugin gem for filtering out profanity.}
         
     | 
| 
       51 
     | 
    
         
            -
              s.test_files = [
         
     | 
| 
       52 
     | 
    
         
            -
                "test/benchmark/fu-fu_benchmark.rb",
         
     | 
| 
       53 
     | 
    
         
            -
                "test/benign_filter_test.rb",
         
     | 
| 
       54 
     | 
    
         
            -
                "test/connection_and_schema.rb",
         
     | 
| 
       55 
     | 
    
         
            -
                "test/destructive_filter_test.rb",
         
     | 
| 
       56 
     | 
    
         
            -
                "test/profanity_filter_test.rb",
         
     | 
| 
       57 
     | 
    
         
            -
                "test/schema.rb",
         
     | 
| 
       58 
     | 
    
         
            -
                "test/test_harness.rb"
         
     | 
| 
       59 
     | 
    
         
            -
              ]
         
     | 
| 
       60 
51 
     | 
    
         | 
| 
       61 
52 
     | 
    
         
             
              if s.respond_to? :specification_version then
         
     | 
| 
       62 
53 
     | 
    
         
             
                s.specification_version = 3
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,33 +1,24 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            --- !ruby/object:Gem::Specification 
     | 
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: profanity_filter
         
     | 
| 
       3 
     | 
    
         
            -
            version: !ruby/object:Gem::Version 
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
     | 
    
         
            -
              segments: 
         
     | 
| 
       7 
     | 
    
         
            -
              - 0
         
     | 
| 
       8 
     | 
    
         
            -
              - 0
         
     | 
| 
       9 
     | 
    
         
            -
              - 2
         
     | 
| 
       10 
     | 
    
         
            -
              version: 0.0.2
         
     | 
| 
       11 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
     | 
    
         
            -
            authors: 
     | 
| 
      
 7 
     | 
    
         
            +
            authors:
         
     | 
| 
       13 
8 
     | 
    
         
             
            - Adam Bair
         
     | 
| 
       14 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       15 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       16 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            date: 2011-04-22 00:00:00 -04:00
         
     | 
| 
       19 
     | 
    
         
            -
            default_executable: 
         
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2011-09-30 00:00:00.000000000Z
         
     | 
| 
       20 
13 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
            description: Allows you to filter profanity using basic replacement or a dictionary
         
     | 
| 
      
 15 
     | 
    
         
            +
              term.
         
     | 
| 
       23 
16 
     | 
    
         
             
            email: adambair@gmail.com
         
     | 
| 
       24 
17 
     | 
    
         
             
            executables: []
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
18 
     | 
    
         
             
            extensions: []
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            extra_rdoc_files: 
         
     | 
| 
      
 19 
     | 
    
         
            +
            extra_rdoc_files:
         
     | 
| 
       29 
20 
     | 
    
         
             
            - README.rdoc
         
     | 
| 
       30 
     | 
    
         
            -
            files: 
     | 
| 
      
 21 
     | 
    
         
            +
            files:
         
     | 
| 
       31 
22 
     | 
    
         
             
            - MIT-LICENSE
         
     | 
| 
       32 
23 
     | 
    
         
             
            - README.rdoc
         
     | 
| 
       33 
24 
     | 
    
         
             
            - Rakefile
         
     | 
| 
         @@ -54,45 +45,29 @@ files: 
     | 
|
| 
       54 
45 
     | 
    
         
             
            - test/profanity_filter_test.rb
         
     | 
| 
       55 
46 
     | 
    
         
             
            - test/schema.rb
         
     | 
| 
       56 
47 
     | 
    
         
             
            - test/test_harness.rb
         
     | 
| 
       57 
     | 
    
         
            -
            has_rdoc: true
         
     | 
| 
       58 
48 
     | 
    
         
             
            homepage: http://github.com/intridea/profanity_filter
         
     | 
| 
       59 
     | 
    
         
            -
            licenses: 
     | 
| 
      
 49 
     | 
    
         
            +
            licenses:
         
     | 
| 
       60 
50 
     | 
    
         
             
            - MIT
         
     | 
| 
       61 
51 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       62 
52 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
            require_paths: 
         
     | 
| 
      
 53 
     | 
    
         
            +
            require_paths:
         
     | 
| 
       65 
54 
     | 
    
         
             
            - lib
         
     | 
| 
       66 
     | 
    
         
            -
            required_ruby_version: !ruby/object:Gem::Requirement 
     | 
| 
      
 55 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       67 
56 
     | 
    
         
             
              none: false
         
     | 
| 
       68 
     | 
    
         
            -
              requirements: 
     | 
| 
       69 
     | 
    
         
            -
              - -  
     | 
| 
       70 
     | 
    
         
            -
                - !ruby/object:Gem::Version 
     | 
| 
       71 
     | 
    
         
            -
                   
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                  - 0
         
     | 
| 
       74 
     | 
    
         
            -
                  version: "0"
         
     | 
| 
       75 
     | 
    
         
            -
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 57 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 58 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 59 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 60 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 61 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       76 
62 
     | 
    
         
             
              none: false
         
     | 
| 
       77 
     | 
    
         
            -
              requirements: 
     | 
| 
       78 
     | 
    
         
            -
              - -  
     | 
| 
       79 
     | 
    
         
            -
                - !ruby/object:Gem::Version 
     | 
| 
       80 
     | 
    
         
            -
                   
     | 
| 
       81 
     | 
    
         
            -
                  segments: 
         
     | 
| 
       82 
     | 
    
         
            -
                  - 0
         
     | 
| 
       83 
     | 
    
         
            -
                  version: "0"
         
     | 
| 
      
 63 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 64 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 65 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 66 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
       84 
67 
     | 
    
         
             
            requirements: []
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
68 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       87 
     | 
    
         
            -
            rubygems_version: 1. 
     | 
| 
      
 69 
     | 
    
         
            +
            rubygems_version: 1.8.8
         
     | 
| 
       88 
70 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       89 
71 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       90 
72 
     | 
    
         
             
            summary: A Rails plugin gem for filtering out profanity.
         
     | 
| 
       91 
     | 
    
         
            -
            test_files: 
         
     | 
| 
       92 
     | 
    
         
            -
            - test/benchmark/fu-fu_benchmark.rb
         
     | 
| 
       93 
     | 
    
         
            -
            - test/benign_filter_test.rb
         
     | 
| 
       94 
     | 
    
         
            -
            - test/connection_and_schema.rb
         
     | 
| 
       95 
     | 
    
         
            -
            - test/destructive_filter_test.rb
         
     | 
| 
       96 
     | 
    
         
            -
            - test/profanity_filter_test.rb
         
     | 
| 
       97 
     | 
    
         
            -
            - test/schema.rb
         
     | 
| 
       98 
     | 
    
         
            -
            - test/test_harness.rb
         
     | 
| 
      
 73 
     | 
    
         
            +
            test_files: []
         
     |