Class: ApacheCrunch::DerivedValueFetcher
- Inherits:
-
Object
- Object
- ApacheCrunch::DerivedValueFetcher
- Defined in:
- lib/element_value_fetcher.rb
Overview
Returns the value of an element derived from one captured directly from the log.
Instance Method Summary collapse
-
#dep_inject!(derivation_rule_finder_cls) ⇒ Object
Handles dependency injection.
-
#fetch(entry, element_name) ⇒ Object
Returns the value for the given name by deriving from an Element in the Entry.
-
#initialize ⇒ DerivedValueFetcher
constructor
A new instance of DerivedValueFetcher.
Constructor Details
#initialize ⇒ DerivedValueFetcher
Returns a new instance of DerivedValueFetcher.
46 47 48 |
# File 'lib/element_value_fetcher.rb', line 46 def initialize @_DerivationRuleFinder = DerivationRuleFinder end |
Instance Method Details
#dep_inject!(derivation_rule_finder_cls) ⇒ Object
Handles dependency injection
51 52 53 |
# File 'lib/element_value_fetcher.rb', line 51 def dep_inject!(derivation_rule_finder_cls) @_DerivationRuleFinder = derivation_rule_finder_cls end |
#fetch(entry, element_name) ⇒ Object
Returns the value for the given name by deriving from an Element in the Entry.
Returns nil if no such value can be derived.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/element_value_fetcher.rb', line 58 def fetch(entry, element_name) # Find the derivation rule that will get us the element we want rule = @_DerivationRuleFinder.find(element_name) return nil if rule.nil? # Get the value of the element from which we're deriving source_element_name = rule.source_name source_element = entry.captured_elements[source_element_name] return nil if source_element.nil? # Do the derivation rule.derive(element_name, source_element.value) end |