Skip to content

Instantly share code, notes, and snippets.

@rjollet
Last active September 23, 2016 14:32
Show Gist options
  • Save rjollet/f1219dfc4d02235a5886687bec0308ae to your computer and use it in GitHub Desktop.
Save rjollet/f1219dfc4d02235a5886687bec0308ae to your computer and use it in GitHub Desktop.
require 'yaml'
require 'csv'
def array_to_hashs(array)
keys = array[0]
data = array[1..-1]
data.map { |values| Hash[keys.zip(values)] }
end
array = CSV.read(ARGV[0], col_sep: "\t")
hashs = array_to_hashs array
File.open(ARGV[1], 'w') do |file|
file.puts hashs.to_yaml
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment