Class: Gluttonberg::Content::Despamilator::Subject
- Inherits:
-
Object
- Object
- Gluttonberg::Content::Despamilator::Subject
- Defined in:
- lib/gluttonberg/content/despamilator/subject.rb,
lib/gluttonberg/content/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.
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
#score ⇒ Object (readonly)
Returns the value of attribute score.
7 8 9 |
# File 'lib/gluttonberg/content/despamilator/subject.rb', line 7 def score @score end |
#text ⇒ Object (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
#matches ⇒ Object
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 |