Class: Dat::Analysis::Registry

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeRegistry

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

#matchersObject

Public: Get the list of known Dat::Analysis::Matcher subclasses

Returns the list of currently known matcher classes.



25
26
27
# File 'lib/dat/analysis/registry.rb', line 25

def matchers
  @known_classes.select {|c| c <= ::Dat::Analysis::Matcher }
end

#wrappersObject

Public: Get the list of known Dat::Analysis::Result subclasses

Returns the list of currently known result wrapper classes.



32
33
34
# File 'lib/dat/analysis/registry.rb', line 32

def wrappers
  @known_classes.select {|c| c <= ::Dat::Analysis::Result }
end