Class: Dat::Analysis::Registry
- Inherits:
-
Object
- Object
- Dat::Analysis::Registry
- Defined in:
- lib/dat/analysis/registry.rb
Overview
Internal: Registry of Dat::Analysis::Matcher and Dat::Analysis::Result
classes. This is used to maintain the mapping of matchers and
results wrappers for a particular Dat::Analysis instance.
Instance Method Summary collapse
-
#add(klass) ⇒ Object
Public: Add a matcher or results wrapper class to the registry.
-
#identify(result) ⇒ Object
Public: Get list of Dat::Analysis::Matcher subclasses for which ‘#match?` is truthy for the given result.
-
#initialize ⇒ Registry
constructor
Public: Create a new Registry instance.
-
#matchers ⇒ Object
Public: Get the list of known Dat::Analysis::Matcher subclasses.
-
#wrappers ⇒ Object
Public: Get the list of known Dat::Analysis::Result subclasses.
Constructor Details
#initialize ⇒ Registry
Public: Create a new Registry instance.
8 9 10 |
# File 'lib/dat/analysis/registry.rb', line 8 def initialize @known_classes = [] end |
Instance Method Details
#add(klass) ⇒ Object
Public: Add a matcher or results wrapper class to the registry
klass - a Dat::Analysis::Matcher subclass or a Dat::Analysis::Result
subclass, to be added to the registry.
Returns the list of currently registered classes.
18 19 20 |
# File 'lib/dat/analysis/registry.rb', line 18 def add(klass) @known_classes << klass end |
#identify(result) ⇒ Object
Public: Get list of Dat::Analysis::Matcher subclasses for which
`#match?` is truthy for the given result.
result - a cooked science mismatch result
Returns a list of matchers initialized with the provided result.
42 43 44 45 46 47 48 |
# File 'lib/dat/analysis/registry.rb', line 42 def identify(result) matchers.inject([]) do |hits, matcher| instance = matcher.new(result) hits << instance if instance.match? hits end end |