Class: Despamilator::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/despamilator/filter.rb

Overview

This class is the base class of all the despamilator filters.

EXAMPLE:

This example is to detect the letter “a”. Put the code in lib/despamilator/filter/detect_letter_a.rb:

require 'despamilator/filter_base'

module DespamilatorFilter

  class DetectLetterA < Despamilator::FilterBase

    def name
      'Detecting the letter A'
    end

    def description
      'Detects the letter "a" in a string for no reason other than a demo'
    end

    def parse text
      if text.downcase.scan(/a/)
      # add 0.1 to the score of the text
      self.append_score = 0.1
    end
  end
end

Instance Method Summary collapse

Instance Method Details

#descriptionObject

The nice description of the filter. Usually no more than a sentence.



36
37
38
# File 'lib/despamilator/filter.rb', line 36

def description
  raise "No description defined for #{self.class}"
end

#nameObject

The one or two word name for the filter.



48
49
50
# File 'lib/despamilator/filter.rb', line 48

def name
  raise "No name defined for #{self.class}"
end

#parse(text) ⇒ Object

This method parses some text. The score is assigned to the same instance.



42
43
44
# File 'lib/despamilator/filter.rb', line 42

def parse text
  raise "No parser defined for #{self.class}"
end