我想将从 CSV 文件解析的值写入 YAML 文件:
home_phone = row['HomePhone']
if home_phone.length == 10
puts "First Name: #{row['first_Name']} - Home Phone: #{home_phone} - Zip Code: #{zip_code}"
elsif home_phone.length == 11 && home_phone.start_with?('1')
home_phone.slice!(0)
puts "First Name: #{row['first_Name']} - Home Phone: #{home_phone} - Zip Code: #{zip_code}"
else
puts "First Name: #{row['first_Name']} - Home Phone: #{"0000000000"} - Zip Code: #{zip_code}"
end
上面的代码用于逐行打印详细信息。从代码中得到的输出是:
First Name: Douglas - Home Phone: 4252745000 - Zip Code: 50309'
'First Name: Aya - Home Phone: 9995901339 - Zip Code: 90210'
'First Name: Audrey - Home Phone: 0 - Zip Code: 05667'
如何将这些值写入 YAML 文件?