class Splam::Rules::WordLength
Public Instance Methods
average(arr)
click to toggle source
# File lib/splam/rules/word_length.rb, line 8 def average(arr) sum(arr) / arr.size end
median(arr)
click to toggle source
# File lib/splam/rules/word_length.rb, line 12 def median(arr) a2 = arr.sort a2[arr.size / 2] unless arr.empty? end
run()
click to toggle source
# File lib/splam/rules/word_length.rb, line 17 def run words = [] words = @body.split(/\s/) words.delete_if { |w| w =~ /^https?\:\/\// } words.collect! { |word| word.size } # Only count word lengths over 10 if words.size > 5 add_score 5, "Average word length over 5" if average(words) > 5 add_score 10, "Average word length over 10" if average(words) > 10 add_score 5, "Median word length over 5" if median(words) > 5 add_score 10, "Median word length over 10" if median(words) > 10 end end
sum(arr)
click to toggle source
Basic array functions
# File lib/splam/rules/word_length.rb, line 4 def sum(arr) arr.inject {|sum,x| sum + x } end