Class: Streamer::FactProviders::HashProvider
- Inherits:
-
Object
- Object
- Streamer::FactProviders::HashProvider
- Defined in:
- lib/streamer/fact_providers/hash_provider.rb
Overview
HashProvider implements the Finder Provider interface
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #find(key) ⇒ Object
-
#initialize(data = nil) ⇒ HashProvider
constructor
A new instance of HashProvider.
Constructor Details
#initialize(data = nil) ⇒ HashProvider
Returns a new instance of HashProvider.
6 7 8 |
# File 'lib/streamer/fact_providers/hash_provider.rb', line 6 def initialize(data = nil) @data = data || {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/streamer/fact_providers/hash_provider.rb', line 5 def data @data end |
Instance Method Details
#find(key) ⇒ Object
10 11 12 13 14 |
# File 'lib/streamer/fact_providers/hash_provider.rb', line 10 def find(key) string_keys = key.split('.') sym_keys = key.split('.').map(&:to_sym) data.dig(*string_keys) || data.dig(*sym_keys) end |