2021-09-05 ruby-csv-helper-method background 一般情况下, 对程序来说处理文本是最友好的 对程序来说, csv的数据比excel更友好 read12345678910require 'csv'def get_array_of_hashes(input_csv_file_path) result = [] CSV.foreach(input_csv_file_path, headers: true, converters: :all) do |row| result << row.to_h.transform_keys(&:to_sym) end resultend write12345678910111213require 'csv'def write_output_as_csv(output, output_csv_file_path) headers = output.first.keys CSV.open(output_csv_file_path, "w") do |csv| csv << headers output.each do |hash| csv << hash.values end endend example workflow123456789101112131415def get_output(datasource) # xxxenddef run input_file_path = "xxx.csv" datasource = get_array_of_hashes(input_file_path) output_csv_file_path = "yyy.csv" output = get_output(datasource) write_output_as_csv(output, output_csv_file_path)endrun 前一篇 disk.usage.scanning 后一篇 local-directory-as-git-remote-repo