Sha256: f7e66be8d8c098e8397b8975fb7968837e87b2cde9c208a2b701dce1696d7a1b

Contents?: true

Size: 637 Bytes

Versions: 5

Compression:

Stored size: 637 Bytes

Contents

require 'despamilator/filter'

module DespamilatorFilter

  class Shouting < Despamilator::Filter

    def name
      'Shouting'
    end

    def description
      'Detects and scores shouting (all caps)'
    end

    def parse subject
      # strip HTML
      text = subject.text.gsub(/<\/?[^>]*>/, "")

      return if text.length < 20

      uppercased = text.scan(/[A-Z][A-Z]+/).join.length
      lowercased = text.count(/[a-z]/)

      if uppercased > 0
        subject.register_match!({
            :score => (uppercased.to_f / (uppercased + lowercased)) * 0.5,
            :filter => self
        })
      end
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
despamilator-2.1.4 lib/despamilator/filter/shouting.rb
despamilator-2.1.3 lib/despamilator/filter/shouting.rb
despamilator-2.1.2 lib/despamilator/filter/shouting.rb
despamilator-2.1.1 lib/despamilator/filter/shouting.rb
despamilator-2.1 lib/despamilator/filter/shouting.rb