Parsing is CSV file in Ruby is very easy. Check out this code:
require "csv" csv_file_path = "ABSOLUTE_PATH_TO_YOUR_CSV_FILE" file = File.open(csv_file_path, "r:ISO-8859-1") csv = CSV.parse file
That’s it. This is how you get the first row:
csv.first
This is how you get the first column of the first row:
csv.first.first
And this is how you iterate over all rows:
csv.each do |row| p row end
Easy! Right?
Don’t forget the “r:ISO-8859-1” part. Otherwise you will get an “ArgumentError: invalid byte sequence in UTF-8” Error.