Last active
December 16, 2015 02:39
-
-
Save DeltaWhy/5364057 to your computer and use it in GitHub Desktop.
Turn a CSV file (where the first line contains the column names) into an array of hashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_csv | |
csv = CSV.parse(STDIN.read) | |
columns = csv[0].map(&:to_sym) | |
csv.delete_at(0) | |
csv.map do |row| | |
Hash[columns.zip(row)] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment