Skip to content

Instantly share code, notes, and snippets.

@chrisseldo
Last active October 28, 2015 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisseldo/7745f46f6c3360f1f5db to your computer and use it in GitHub Desktop.
Save chrisseldo/7745f46f6c3360f1f5db to your computer and use it in GitHub Desktop.
CSV Read/Parse -- Ruby
require 'CSV'
read_csv = CSV.read(file_name)
headers = read_csv.shift.map {|i| i.to_s }
string_data = read_csv.map {|row| row.map {|cell| cell.to_s } }
array_of_hashes = string_data.map {|row| Hash[*headers.zip(row).flatten] }
(tag_header, tag_data) = [headers, array_of_hashes]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment