Created
April 26, 2022 19:05
-
-
Save gschanuel/7ab22190481d7e7efa18d5a0fb0e816f 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 | |
class Foo | |
#def values = hash.to_json | |
end | |
val = {} | |
Foo.new.values.each do |x| | |
val = val.deep_merge(x) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment