Class: Splam::Rules::Fuzz
- Inherits:
-
Splam::Rule
- Object
- Splam::Rule
- Splam::Rules::Fuzz
- Defined in:
- lib/splam/rules/fuzz.rb
Class Attribute Summary collapse
-
.bad_word_score ⇒ Object
Returns the value of attribute bad_word_score.
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_score ⇒ Object
Returns the value of attribute bad_word_score.
3 4 5 |
# File 'lib/splam/rules/fuzz.rb', line 3 def bad_word_score @bad_word_score end |
Instance Method Details
#run ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/splam/rules/fuzz.rb', line 8 def run patterns = [/^(\d[a-z])/, /(\d[a-z][A-Z]\w+)/, /(\b\w+\d\.txt)/, /(;\d+;)/ ] ignore_if = [%r{vendor/rails}, /EXC_BAD_ACCESS/, /JavaAppLauncher/, %r{Contents/MacOS}, %r{/Library/}] matches = 0 # looks like a stack trace ignore_if.each do |pattern| return if @body.scan(pattern) end patterns.each do |pattern| results = @body.scan(pattern) if results && results.size > 0 add_score((self.class.bad_word_score * results.size), "bad pattern match: '#{$1}'") end matches += results.size end add_score matches.size ** 4, "Aggregate number of bad patterns was #{matches}." if matches > 1 end |