Class: DespamilatorFilter::Shouting
- Inherits:
-
Despamilator::Filter
- Object
- Despamilator::Filter
- DespamilatorFilter::Shouting
- Defined in:
- lib/despamilator/filter/shouting.rb
Instance Method Summary collapse
Instance Method Details
#description ⇒ Object
11 12 13 |
# File 'lib/despamilator/filter/shouting.rb', line 11 def description 'Detects and scores shouting (all caps)' end |
#name ⇒ Object
7 8 9 |
# File 'lib/despamilator/filter/shouting.rb', line 7 def name 'Shouting' end |
#parse(subject) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/despamilator/filter/shouting.rb', line 15 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 |