Amending form of Array in Ruby -
im hoping can help.
i have array being returned call google spreadsheet returns this:
{"2014 week"=>"01", "weekly reach"=>"2.93"} {"2014 week"=>"02", "weekly reach"=>"3.37"} {"2014 week"=>"03", "weekly reach"=>"3.24"} {"2014 week"=>"04", "weekly reach"=>"2.39"} {"2014 week"=>"05", "weekly reach"=>"2.96"} {"2014 week"=>"06", "weekly reach"=>"6.31"} {"2014 week"=>"07", "weekly reach"=>"9.11"} {"2014 week"=>"08", "weekly reach"=>"8.59"} {"2014 week"=>"09", "weekly reach"=>"2.11"} {"2014 week"=>"10", "weekly reach"=>"2.24"} {"2014 week"=>"11", "weekly reach"=>"1.88"} {"2014 week"=>"12", "weekly reach"=>"2"} {"2014 week"=>"13", "weekly reach"=>"3"} {"2014 week"=>"14", "weekly reach"=>"2"} {"2014 week"=>"15", "weekly reach"=>"2"} {"2014 week"=>"16", "weekly reach"=>"3"}
essentially, want amend array in form:
result = [{x:1, y: 2.93}, {x:2, y:3.37}, {x:3, y:3.24}...]
due noob status in ruby i'm struggling believe solution lies in arr.map!, function if understood wouldn't require question! hugely appreciated.
map
returns array consisting of result of block evaluation each element. should have:
result = array.map |data| { x: data['2014 week'], y: data['reach'] } end
Comments
Post a Comment