I am trying to parse some output from a query using the mysql2 gem.
Previously, I would use:
response = JSON.parse(response.body)
a = response.map{|s| {label: s['Category'], value: s['count'].to_i} }
Now with the mysql2 query:
results = db.query(sql)
results.map do |row|
puts row
end
Output
{"Category"=>"Food", "count"=>22}
{"Category"=>"Drinks", "count"=>12}
{"Category"=>"Alcohol", "count"=>9}
{"Category"=>"Home", "count"=>7}
{"Category"=>"Work", "count"=>2}
'Category' to ':label' and 'count' to ':value'.
results = db.query(sql)
results.map do |row|
{label: row['Category'], value: row['count'].to_i} }
end
Desired Output
{:label=>"Food", :value=>22}
{:label=>"Drinks", :value=>12}
{:label=>"Alcohol", :value=>9}
{:label=>"Home", :value=>7}
{:label=>"Work", :value=>2}