Class: Streamer::FactProviders::HashProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/streamer/fact_providers/hash_provider.rb

Overview

HashProvider implements the Finder Provider interface

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (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