def get_vhost_data
structure_hash = { ... } # The first hash above, etc.
vhost_data = [] # We're returning an array, so initialize one
# Loop through the containing hash. Each key will be our scope, so we need to
# access that
demo_structurestructure_hash.each do |scope, scope_hash|
# We need to transform and add to the data in these hashes.
scope_hash.each do |code, url|
# Best to return a new hash to house the old values + the transformed ones
demo_data = {}
# The "scope" key from the outer hash needs to be changed conditionally
demo_data[:scope] = scope == 'store_view' ? scope.gsub('store_view', 'store') : scope
# The rest of the data is fine
demo_data[:code] = code
demo_data[:url] = url
# Add the newly-created hash to the containing array
vhost_data << demo_data
end
end
# Return the containing array
vhost_data
end
def get_vhost_data_refactor
demo_structurestructure_hash = {...}
demo_structurestructure_hash.each_with_object([]) do |(scope, scope_hash), vhost_arr|
scope_hash.each_with_object({}) do |(code, url), data_hash|
data_hash[:scope] = scope == 'store_view' ? scope.gsub('store_view', 'store') : scope
data_hash[:code] = code
data_hash[:url] = url
vhost_arr << data_hash
end
end
end