Class: Gluttonberg::Content::DespamilatorFilter::Shouting

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

Instance Method Summary collapse

Instance Method Details

#descriptionObject



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

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

#nameObject



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

def name
  'Shouting'
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/shouting.rb', line 17

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