Class: Despamilator::Subject
- Inherits:
-
Object
- Object
- Despamilator::Subject
- Defined in:
- lib/despamilator/subject.rb,
lib/despamilator/subject/text.rb
Defined Under Namespace
Classes: Text
Instance Attribute Summary collapse
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text) ⇒ Subject
constructor
A new instance of Subject.
- #matches ⇒ Object
- #register_match!(details) ⇒ Object
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
#score ⇒ Object (readonly)
Returns the value of attribute score.
5 6 7 |
# File 'lib/despamilator/subject.rb', line 5 def score @score end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
5 6 7 |
# File 'lib/despamilator/subject.rb', line 5 def text @text end |
Instance Method Details
#matches ⇒ Object
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 |