Class: JobParser::Scorer
- Inherits:
-
Object
- Object
- JobParser::Scorer
- Defined in:
- lib/jobparser/scorer.rb
Instance Attribute Summary collapse
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
Instance Method Summary collapse
-
#initialize ⇒ Scorer
constructor
A new instance of Scorer.
- #score_for(str) ⇒ Object
- #store(str, worth) ⇒ Object
- #store_and_score(str, worth) ⇒ Object
- #top_match ⇒ Object
Constructor Details
#initialize ⇒ Scorer
Returns a new instance of Scorer.
5 6 7 |
# File 'lib/jobparser/scorer.rb', line 5 def initialize @matches = {} end |
Instance Attribute Details
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
3 4 5 |
# File 'lib/jobparser/scorer.rb', line 3 def matches @matches end |
Instance Method Details
#score_for(str) ⇒ Object
20 21 22 |
# File 'lib/jobparser/scorer.rb', line 20 def score_for(str) @matches[str].nil? ? 0 : @matches[str].score end |
#store(str, worth) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/jobparser/scorer.rb', line 9 def store(str, worth) match = nil if match = @matches[str] match = Match.new(str, worth, match.score) else match = Match.new(str, worth) end @matches[str] = match match end |
#store_and_score(str, worth) ⇒ Object
28 29 30 |
# File 'lib/jobparser/scorer.rb', line 28 def store_and_score(str, worth) store(str, worth).and_score_now end |
#top_match ⇒ Object
24 25 26 |
# File 'lib/jobparser/scorer.rb', line 24 def top_match @matches.select { |k, v| v.score > 0 }.max_by { |k, v| v.score }.first end |