0
にcsvファイルの日付を追加:は、どのように私は次の内容のファイルを持っているデータベース
私が取得するコードを以下している:私はこの方法でデータベースを作成し
purchaser name item description item price purchase count merchant address merchant name
João Silva R$10 off R$20 of food 10.0 2 987 Fake St Bob's Pizza
Amy Pond R$30 of awesome for R$10 10.0 5 456 Unreal Rd Tom's Awesome Shop
Marty McFly R$20 Sneakers for R$5 5.0 1 123 Fake St Sneaker Store Emporium
Snake Plissken R$20 Sneakers for R$5 5.0 4 123 Fake St Sneaker Store Emporium
データ:
require 'csv'
CSV.foreach('myfile.txt', col_sep: "\t", headers: true).map do |row|
row.to_h
end
私はそれを絞ると、次のハッシュを取得します。
[{"purchaser name"=>"João Silva", "item description"=>"R$10 off R$20 of food", "item price"=>"10.0", "purchase count"=>"2", "merchant address"=>"987 Fake St", "merchant name"=>"Bob's Pizza"}, {"purchaser name"=>"Amy Pond", "item description"=>"R$30 of awesome for R$10", "item price"=>"10.0", "purchase count"=>"5", "merchant address"=>"456 Unreal Rd", "merchant name"=>"Tom's Awesome Shop"}, {"purchaser name"=>"Marty McFly", "item description"=>"R$20 Sneakers for R$5", "item price"=>"5.0", "purchase count"=>"1", "merchant address"=>"123 Fake St", "merchant name"=>"Sneaker Store Emporium"}, {"purchaser name"=>"Snake Plissken", "item description"=>"R$20 Sneakers for R$5", "item price"=>"5.0", "purchase count"=>"4", "merchant address"=>"123 Fake St", "merchant name"=>"Sneaker Store Emporium"}]
このハッシュの各アイテムをデータベースの適切なテーブルに配置するにはどうすればよいですか?
[parse of ruby]の可能な複製(https://stackoverflow.com/questions/47135220/parse-of-txt-on-ruby) – Ilya