Class: Despamilator::Subject

Inherits:
Object
  • Object
show all
Defined in:
lib/despamilator/subject.rb,
lib/despamilator/subject/text.rb

Defined Under Namespace

Classes: Text

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Subject

Returns a new instance of Subject.



7
8
9
10
11
# File 'lib/despamilator/subject.rb', line 7

def initialize text
  @score = 0.0
  @matches = {}
  @text = Despamilator::Subject::Text.new(text)
end

Instance Attribute Details

#scoreObject (readonly)

Returns the value of attribute score.



5
6
7
# File 'lib/despamilator/subject.rb', line 5

def score
  @score
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/despamilator/subject.rb', line 5

def text
  @text
end

Instance Method Details

#matchesObject



21
22
23
24
25
26
27
# File 'lib/despamilator/subject.rb', line 21

def matches
  @matches.map do |filter, score|
    {:filter => filter, :score => score}
  end.sort do |a, b|
    b[:score] <=> a[:score]
  end
end

#register_match!(details) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/despamilator/subject.rb', line 13

def register_match! details
  @score += details[:score] || raise('A score must be supplied')
  filter = details[:filter] || raise('A filter must be supplied')

  @matches[filter] ||= 0.0
  @matches[filter] += details[:score]
end