Created
August 26, 2011 13:19
-
-
Save sr75/1173384 to your computer and use it in GitHub Desktop.
csv_to_array
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 csv_to_array(file_location) | |
csv = CSV::parse(File.open(file_location, 'r') {|f| f.read }) | |
fields = csv.shift | |
csv.collect { |record| Hash[*(0..(fields.length - 1)).collect {|index| [fields[index],record[index].to_s] }.flatten ] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment