Sha256: 0f6bf1e69ab27a1b693971b1a920342d95090a9f0a8a1f5540dea8dcb548b294

Contents?: true

Size: 1.22 KB

Versions: 12

Compression:

Stored size: 1.22 KB

Contents

module Gluttonberg
  module Content
    require 'despamilator/filter'

    module DespamilatorFilter

      class NumbersAndWords < Despamilator::Filter

        def parse subject
          text = tidy_text(subject)

          [
                  /\w\d+/,
                  /\d+\w/,
                  /\d+($|\b)/
          ].each do |regexp|
            matches = text.scan(regexp)

            next if matches.empty?

            matches.each do |to_remove|
              to_remove = to_remove.to_s
              text.sub!(to_remove, '') unless to_remove.empty?
              subject.register_match!({:score => 0.1, :filter => self})
            end
          end
        end

        def name
          'Numbers next to words'
        end

        def description
          'Detects unusual number/word combinations'
        end

        private

        def tidy_text subject
          text = subject.text.without_uris
          text.downcase!

          # strip out "good numbers"
          text.gsub!(/h[1-6]/, '')
          text.gsub!(/(^|\b)\d+($|\b)/, '')
          text.gsub!(/(^|\b)\d+(,|\.)\d+($|\b)/, '')
          text.gsub!(/(^|\b)\d+(st|nd|rd|th)($|\b)/, '')

          text
        end
      end

    end
  end #Content
end #Gluttonberg

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gluttonberg-core-3.0.2 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb
gluttonberg-core-3.0.1 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb
gluttonberg-core-3.0.0 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb
gluttonberg-core-2.6.4 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb
gluttonberg-core-2.6.3 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb
gluttonberg-core-2.6.2 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb
gluttonberg-core-2.6.1 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb
gluttonberg-core-2.6.0 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb
gluttonberg-core-2.5.9 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb
gluttonberg-core-2.5.8 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb
gluttonberg-core-2.5.7 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb
gluttonberg-core-2.5.6 lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb