Class: Linkage::ScoreRecorder
- Inherits:
-
Object
- Object
- Linkage::ScoreRecorder
- Defined in:
- lib/linkage/score_recorder.rb
Overview
ScoreRecorder is responsible for observing a set of Comparator for changes and saving matches to a ScoreSet via Linkage::ScoreSet#add_score.
Instance Method Summary collapse
-
#initialize(comparators, score_set, primary_keys) ⇒ ScoreRecorder
constructor
A new instance of ScoreRecorder.
- #start ⇒ Object
- #stop ⇒ Object
- #update(comparator, record_1, record_2, score) ⇒ Object
Constructor Details
#initialize(comparators, score_set, primary_keys) ⇒ ScoreRecorder
Returns a new instance of ScoreRecorder.
8 9 10 11 12 |
# File 'lib/linkage/score_recorder.rb', line 8 def initialize(comparators, score_set, primary_keys) @comparators = comparators @score_set = score_set @primary_keys = primary_keys end |
Instance Method Details
#start ⇒ Object
14 15 16 17 18 19 |
# File 'lib/linkage/score_recorder.rb', line 14 def start @comparators.each do |comparator| comparator.add_observer(self) end @score_set.open_for_writing end |
#stop ⇒ Object
28 29 30 31 32 33 |
# File 'lib/linkage/score_recorder.rb', line 28 def stop @score_set.close @comparators.each do |comparator| comparator.delete_observer(self) end end |
#update(comparator, record_1, record_2, score) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/linkage/score_recorder.rb', line 21 def update(comparator, record_1, record_2, score) index = @comparators.index(comparator) primary_key_1 = record_1[@primary_keys[0]] primary_key_2 = record_2[@primary_keys[1]] @score_set.add_score(index + 1, primary_key_1, primary_key_2, score) end |