'Ruby on rails get and save values on array

So I'm working with a Weather API and that's give the rainProb field with 4 values with 8 hours difference and i want to assign this value to every hour.

In other words that is:

10 => 02
10 => 03
10 => 04
10 => 05
10 => 06
10 => 07
10 => 08
0  => 09

... So thats the code:

 "probPrecipitacion"=>

  [{"value"=>"10", "periodo"=>"0208"},

   {"value"=>"0", "periodo"=>"0814"},

   {"value"=>"5", "periodo"=>"1420"},

   {"value"=>"0", "periodo"=>"2002"}],

This are the meanings of the "periodo"

0208 = 02:00 to 08:00

0814 = 08:00 to 14:00

1420 = 14:00 to 20:00

2002 = 20:00 to 20:00

And to get the code from de json i do this:

arr_rain_prob = json.dig(0,'prediccion','dia',1,'probPrecipitacion').map{ |e| e['value']}
arr_periodo_prob = json.dig(0,'prediccion','dia',1,'probPrecipitacion').map{ |e| e['periodo']}  

hourly_forecast.rain = arr_rain_prob[hour] #hour is and iterative that goes to 0 to 23

arr_rain_prob contains this values = 10 0 5 0 arr_periodo_prob contains this values = 0208 0814 1420 2002

Can someone help?

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source