Class: DespamilatorFilter::WeirdPunctuation

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

Instance Method Summary collapse

Instance Method Details

#descriptionObject



11
12
13
# File 'lib/despamilator/filter/weird_punctuation.rb', line 11

def description
  'Detects unusual use of punctuation.'
end

#nameObject



7
8
9
# File 'lib/despamilator/filter/weird_punctuation.rb', line 7

def name
  'Weird Punctuation'
end

#parse(subject) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/despamilator/filter/weird_punctuation.rb', line 15

def parse subject
  text = subject.text.without_uris.downcase

  text.gsub!(/\w&\w/, 'xx')
  text.gsub!(/[a-z](!|\?)(\s|$)/, 'x')
  text.gsub!(/(?:#{punctuation}){20,}/, '')
  matches = text.remove_and_count!(/(?:\W|\s|^)(#{punctuation})/)
  matches += text.remove_and_count!(/\w,\w/)
  matches += text.remove_and_count!(/\w\w\.\w/)
  matches += text.remove_and_count!(/\w\.\w\w/)
  matches += text.remove_and_count!(/(#{punctuation})(#{punctuation})/)
  matches += text.remove_and_count!(/(#{punctuation})$/)
  matches += text.remove_and_count!(/(?:\W|\s|^)\d+(#{punctuation})/)

  subject.register_match!({:score => 0.03 * matches, :filter => self}) if matches > 0
end