Class: Splam::Rules::ArmsRace

Inherits:
Splam::Rule show all
Defined in:
lib/splam/rules/arms_race.rb

Class Attribute Summary collapse

Attributes inherited from Splam::Rule

#body, #reasons, #score, #suite, #weight

Instance Method Summary collapse

Methods inherited from Splam::Rule

#add_score, inherited, #initialize, #line_safe?, #name, run

Constructor Details

This class inherits a constructor from Splam::Rule

Class Attribute Details

.bad_word_scoreObject

Returns the value of attribute bad_word_score.



3
4
5
# File 'lib/splam/rules/arms_race.rb', line 3

def bad_word_score
  @bad_word_score
end

Instance Method Details

#runObject

This is where you put banned domain names or otherwise



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/splam/rules/arms_race.rb', line 9

def run
  shitty_sites = ["inquisitr", "beeplog"]    
  shitty_sites.each do |word|
    results = @body.downcase.scan(word) 
    if results && results.size > 0
      add_score((self.class.bad_word_score ** results.size), "stupid site: '#{word}'")
      @body.scan(/<a[^>]+>(.*?)<\/a>/).each do |match|
        add_score self.class.bad_word_score * 4 * match[0].scan(word).size, "nasty word inside a link: #{word}"
      end
      @body.scan(/<a(.*?)>/).each do |match|
        add_score self.class.bad_word_score * 4 * match[0].scan(word).size, "nasty word inside a URL: #{word}"
      end
    end
  end
end