Module: ObjectTraverser

Instance Method Summary collapse

Instance Method Details

#extract_value(keys, value) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/inspec/utils/object_traversal.rb', line 2

def extract_value(keys, value)
  return nil if value.nil?

  key = keys.shift
  return nil if key.nil?

  # if the current value is not a Hash or Array, it is undefined
  # behavior so value will be assigned nil by default.
  value = if value.is_a?(Array)
            extract_from_array(key, value)
          elsif value.is_a?(Hash)
            extract_from_hash(key, value)
          end

  # if there are no more keys, just return the value
  return value if keys.first.nil?

  # if there are more keys, extract more
  extract_value(keys.clone, value)
end