{"url":"https://ikm.hatenablog.jp/entry/2013/01/29/161103","author_name":"a2ikm","blog_title":"There's an echo in my head","blog_url":"https://ikm.hatenablog.jp/","provider_name":"Hatena Blog","version":"1.0","type":"rich","image_url":null,"width":"100%","title":"CSV\u3092YAML\u306b\u66f8\u304d\u63db\u3048\u308b","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fikm.hatenablog.jp%2Fentry%2F2013%2F01%2F29%2F161103\" title=\"CSV\u3092YAML\u306b\u66f8\u304d\u63db\u3048\u308b - There&#39;s an echo in my head\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","height":"190","published":"2013-01-29 16:11:03","author_url":"https://blog.hatena.ne.jp/a2ikm/","provider_url":"https://hatena.blog","description":"\u6a19\u6e96\u6dfb\u4ed8\u306ecsv\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u4f7f\u3044\u65b9\u3092\u3044\u3064\u3082\u5fd8\u308c\u308b\u306e\u3067\u30e1\u30e2\u3063\u3066\u304a\u304f\u3002 require \"csv\" require \"yaml\" hash = {} csv = CSV.read(path_to_csv, headers: :first_row) csv.each do |row| id = row[\"id\"] hash[\"foo_#{id}\"] = { \"id\" => id, \"name\" => row[\"name\"], \"value\" => row[\"value\"] } end File.open(path_to_yaml, \"w\") { |f| f.write(hash.to_yaml) }\u2026","categories":["ruby"]}