Class: Gluttonberg::Content::DespamilatorFilter::WeirdPunctuation

Inherits:
Gluttonberg::Content::Despamilator::Filter show all
Defined in:
lib/gluttonberg/content/despamilator/filter/weird_punctuation.rb

Instance Method Summary collapse

Instance Method Details

#descriptionObject



13
14
15
# File 'lib/gluttonberg/content/despamilator/filter/weird_punctuation.rb', line 13

def description
  'Detects unusual use of punctuation.'
end

#nameObject



9
10
11
# File 'lib/gluttonberg/content/despamilator/filter/weird_punctuation.rb', line 9

def name
  'Weird Punctuation'
end

#parse(subject) ⇒ Object



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

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