-
-
Save sixtyfive/4a710cc1d46a478b720b4b82e41fc17d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
file = File.read('./event.json') | |
event = JSON.parse(file) | |
keys = event['windows']['perfmon']['metrics'] | |
hash=keys.map { |key, value| | |
key.split('_').reverse.reduce(value) { | |
|key_value, next_key| { | |
next_key => key_value | |
} | |
} | |
} | |
class Hash | |
def deep_merge(other_hash, &block) | |
dup.deep_merge!(other_hash, &block) | |
end | |
# Same as +deep_merge+, but modifies +self+. | |
def deep_merge!(other_hash, &block) | |
merge!(other_hash) do |key, this_val, other_val| | |
if this_val.is_a?(Hash) && other_val.is_a?(Hash) | |
this_val.deep_merge(other_val, &block) | |
elsif block_given? | |
block.call(key, this_val, other_val) | |
else | |
other_val | |
end | |
end | |
end | |
end | |
val = {} | |
hash.each do |x| | |
val.deep_merge!(x) | |
end | |
puts val.to_json | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment