mardi 27 décembre 2016

Not able to place csv data in a Hash

I have a csv file with two columns:

PPS_Id Amount
123    100
1234   150

I read data from this file and insert in a array using the code below:

CSV.foreach("filename.CSV", headers: true) do |row|
file_details << row.inspect # hash
end

I am then trying to push the data in the file_details into a hash with PPS_Id as key and Amount as Value, I am using the code below:

file_details_hash = Hash.new
  file_details.each { |x|  
    file_details_hash[x['PPS_Id']] = x['Amount']
}

But when I print the result I get nothing just {"PPS_Id"=>"Amount"}

Can you please help

Aucun commentaire:

Enregistrer un commentaire