Created
December 29, 2014 21:05
-
-
Save honorelsu/705979fa00e9a4c5f0d3 to your computer and use it in GitHub Desktop.
CSV to 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
require 'CSV' | |
require 'easy_diff' | |
dcsexport = ARGV[0] | |
opsexport = ARGV[1] | |
def csv_to_array(file_location) | |
csv = CSV::parse(File.open(file_location, 'r') {|f| f.read}) | |
fields = csv.shift | |
csv.collect {|record| Hash[*fields.zip(record).flatten]} | |
end | |
dcs = csv_to_array(dcsexport) | |
ops = csv_to_array(opsexport) | |
puts "The exported file is of type #{dcs.class}" | |
puts "The exported file's first row is of type #{dcs.first.class}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment