Class: Linkage::ResultSet
- Inherits:
-
Object
- Object
- Linkage::ResultSet
- Defined in:
- lib/linkage/result_set.rb
Overview
A ResultSet is a convenience class for wrapping a ScoreSet and a MatchSet. Most of the time, you'll want to use the same storage format for both scores and matches. ResultSet provides a way to group both sets together.
The default implementation of ResultSet merely returns whatever ScoreSet and MatchSet you pass to it during creation (see #initialize). However, ResultSet can be subclassed to provide easy initialization of sets of the same format. Currently there are two subclasses:
- CSV (Linkage::ResultSets::CSV)
- Database (Linkage::ResultSets::Database)
If you want to implement a custom ResultSet, create a class that inherits ResultSet and defines both #score_set and #match_set to return a ScoreSet and MatchSet respectively. You can then register that class via ResultSet.register to make it easier to use.
Direct Known Subclasses
Class Method Summary collapse
-
.klass_for(name) ⇒ Class?
(also: [])
Return a registered ResultSet subclass or
nil
if it doesn't exist. -
.register(name, klass) ⇒ Object
Register a new result set.
Instance Method Summary collapse
-
#initialize(score_set, match_set) ⇒ ResultSet
constructor
A new instance of ResultSet.
-
#match_set ⇒ MatchSet
Returns a MatchSet.
-
#score_set ⇒ ScoreSet
Returns a ScoreSet.
Constructor Details
#initialize(score_set, match_set) ⇒ ResultSet
Returns a new instance of ResultSet.
56 57 58 59 |
# File 'lib/linkage/result_set.rb', line 56 def initialize(score_set, match_set) @score_set = score_set @match_set = match_set end |
Class Method Details
.klass_for(name) ⇒ Class? Also known as: []
Return a registered ResultSet subclass or nil
if it doesn't exist.
48 49 50 |
# File 'lib/linkage/result_set.rb', line 48 def klass_for(name) @result_set ? @result_set[name] : nil end |
.register(name, klass) ⇒ Object
Register a new result set. Subclasses must define #score_set and
#match_set. Otherwise, an ArgumentError
will be raised when you try
to call register.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/linkage/result_set.rb', line 27 def register(name, klass) methods = klass.instance_methods missing = [] unless methods.include?(:score_set) missing.push("#score_set") end unless methods.include?(:match_set) missing.push("#match_set") end unless missing.empty? raise ArgumentError, "class must define #{missing.join(" and ")}" end @result_set ||= {} @result_set[name] = klass end |