Class: DespamilatorFilter::NumbersAndWords

Inherits:
Despamilator::Filter show all
Defined in:
lib/despamilator/filter/numbers_and_words.rb

Instance Method Summary collapse

Instance Method Details

#descriptionObject



31
32
33
# File 'lib/despamilator/filter/numbers_and_words.rb', line 31

def description
  'Detects unusual number/word combinations'
end

#nameObject



27
28
29
# File 'lib/despamilator/filter/numbers_and_words.rb', line 27

def name
  'Numbers next to words'
end

#parse(subject) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/despamilator/filter/numbers_and_words.rb', line 7

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