Ruby: convert deep-nested hashes into shallow sparse hashes (and back again)