Class: JobParser::Scorer

Inherits:
Object
  • Object
show all
Defined in:
lib/jobparser/scorer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScorer

Returns a new instance of Scorer.



5
6
7
# File 'lib/jobparser/scorer.rb', line 5

def initialize
  @matches = {}
end

Instance Attribute Details

#matchesObject (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_matchObject



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