#!/usr/bin/env ruby # example: ruby task_p2.rb require 'json' require 'yaml' def set(hash, path, val) parts = path.split('.') scope = hash parts[0..-2].each do |hop| scope[hop] ||= {} scope = scope.fetch(hop) raise "Could not add value into scalar property #{path}" unless scope.is_a?(Hash) end scope[parts[-1]] = val end def build_tree(data) res = {} data.each do |k, v| set(res, k, v) end res end incoming_file = JSON.pretty_generate(YAML.load_file('translations_simple.yml')) hash = JSON.parse(incoming_file) res = build_tree(hash).to_yaml puts res File.write('./translations.yml', res)