Class: BabelDiff::HashFlattener

Inherits:
Struct
  • Object
show all
Defined in:
lib/babel_diff/yaml_differ.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hashObject

Returns the value of attribute hash

Returns:

  • (Object)

    the current value of hash



66
67
68
# File 'lib/babel_diff/yaml_differ.rb', line 66

def hash
  @hash
end

Instance Method Details

#flat_hashObject



81
82
83
# File 'lib/babel_diff/yaml_differ.rb', line 81

def flat_hash
  @_flat_hash ||= {}
end

#flatten(current_hash = hash, keys = []) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/babel_diff/yaml_differ.rb', line 68

def flatten(current_hash = hash, keys = [])
  current_hash.each do |key, value|
    new_keys = keys.dup << key
    if value.is_a? Hash
      flatten(value, new_keys)
    else
      flat_hash[new_keys.join(".")] = value
    end
  end

  flat_hash
end