Class: Linkage::MatchSet Abstract
- Inherits:
-
Object
- Object
- Linkage::MatchSet
- Defined in:
- lib/linkage/match_set.rb
Overview
A MatchSet is responsible for keeping track of matches. After the scoring process, a Matcher uses scores from a ScoreSet to calculate which record pairs match. Those pairs are then recorded by a MatchRecorder to a MatchSet.
MatchSet is the superclass of implementations for different formats. Currently there are two formats for storing matches:
- CSV (Linkage::MatchSets::CSV)
- Database (Linkage::MatchSets::Database)
See the documentation for match set you're interested in for more information.
If you want to implement a custom MatchSet, create a class that inherits MatchSet and defines at least #add_match. You can then register that class via MatchSet.register.
Direct Known Subclasses
Class Method Summary collapse
-
.klass_for(name) ⇒ Class?
(also: [])
Return a registered MatchSet subclass or
nil
if it doesn't exist. -
.register(name, klass) ⇒ Object
Register a new match set.
Instance Method Summary collapse
-
#add_match(id_1, id_2, score) ⇒ Object
abstract
Add a match to the MatchSet.
-
#close ⇒ Object
This is called by Linkage::MatchRecorder#stop, after all matches have been added.
-
#open_for_writing ⇒ Object
This is called by Linkage::MatchRecorder#start, before any matches are added via #add_match.
Class Method Details
.klass_for(name) ⇒ Class? Also known as: []
Return a registered MatchSet subclass or nil
if it doesn't exist.
42 43 44 |
# File 'lib/linkage/match_set.rb', line 42 def klass_for(name) @match_sets ? @match_sets[name] : nil end |
.register(name, klass) ⇒ Object
Register a new match set. Subclasses must define at least #add_match,
otherwise an ArgumentError
will be raised.
28 29 30 31 32 33 34 35 36 |
# File 'lib/linkage/match_set.rb', line 28 def register(name, klass) methods = klass.instance_methods(false) unless methods.include?(:add_match) raise ArgumentError, "class must define #add_match" end @match_sets ||= {} @match_sets[name] = klass end |
Instance Method Details
#add_match(id_1, id_2, score) ⇒ Object
Add a match to the MatchSet. Subclasses must redefine this.
60 61 62 |
# File 'lib/linkage/match_set.rb', line 60 def add_match(id_1, id_2, score) raise NotImplementedError end |
#close ⇒ Object
This is called by Linkage::MatchRecorder#stop, after all matches have been added. Subclasses can redefine this to perform any teardown needed.
66 67 |
# File 'lib/linkage/match_set.rb', line 66 def close end |
#open_for_writing ⇒ Object
This is called by Linkage::MatchRecorder#start, before any matches are added via #add_match. Subclasses can redefine this to perform any setup needed for saving matches.
51 52 |
# File 'lib/linkage/match_set.rb', line 51 def open_for_writing end |