If I have an array of months like:
["05", "06", "07", "08", "09", "10", "11", "12", "01", "02", "03", "04", "05"]
And a hash of a month value and a month_sum:
[{"month"=>5, "month_sum"=>20}, {"month"=>4, "month_sum"=>100}]
How do I merge the hash into the array so I get something like?
[{"05" => 20}, {"07" => 0}, {"08" => 0}, {"09" => 0}, {"10" => 0}, {"11" => 0}, {"12" => 0}, {"01" => 0}, {"02" => 0}, {"03" => 0}, {"04" => 100}, {"05" => 0}, {"06" => 0}]
Edit
The month array is generated from:
date_from = Date.parse(params[:search][:date_from])
date_to = Date.parse(params[:search][:date_to])
date_range = date_from..date_to
date_months = date_range.map {|d| Date.new(d.year, d.month, 1) }.uniq
@date_range = date_months.map {|d| d.strftime "%m" }
So a caveat is that if the range is over, say a two year period, the array will have duplicate month-values. I suppose I need to add the year into that array?
Is there a better way to do this?
The end goal here is to get a hash or array for highcharts to display monthly sums of fuel usage for particular vehicles. (just so you have some context).
{"05" ...}should have"20"and not the second one? 2. By what rule is{"06" ...}inserted into the expected output? Is there a systematic rule here, or is it just your sloppiness?