Class: Gluttonberg::Content::Despamilator::Subject

Inherits:
Object
  • Object
show all
Defined in:
lib/gluttonberg/content/despamilator/subject.rb,
lib/gluttonberg/content/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.



9
10
11
12
13
# File 'lib/gluttonberg/content/despamilator/subject.rb', line 9

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.



7
8
9
# File 'lib/gluttonberg/content/despamilator/subject.rb', line 7

def score
  @score
end

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'lib/gluttonberg/content/despamilator/subject.rb', line 7

def text
  @text
end

Instance Method Details

#matchesObject



23
24
25
26
27
28
29
# File 'lib/gluttonberg/content/despamilator/subject.rb', line 23

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



15
16
17
18
19
20
21
# File 'lib/gluttonberg/content/despamilator/subject.rb', line 15

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