有三个哈希值。每个散列都会产生一个键/值对。
当合并并输出到一个 json 文件时,唯一可见的 k/v 对是那些有数据的。
例如:
employee_hours[ name ] = {"Hours" => hours}
employee_revenue [ name ] = {"Revenue" => revenue}
employee_activations [ name ] = {"Activations" => activations}
如果任何 k/v 对不存在,我需要将它们包含在输出中,其值为0.00
.
我试图简单地在每个哈希表中包含来自其他哈希的空 k/v 对,但是当合并时,它们会覆盖现有值。
employee_hours[ name ] = {"Hours" => hours, "Revenue" = "", Activations = ""}
employee_revenue [ name ] = {"Hours" => "", "Revenue" => revenue, Activations = ""}
employee_activations [ name ] = {"Hours" => "", "Revenue" => "", "Activations" => activations}
编辑
我当前的代码在这里列出:https ://gist.github.com/hnanon/766a0d6b2b0f9d9d03fd