You should use the standard CSV library. It's FasterCSV plus support for Ruby 1.9's m17n encoding engine.
Back to your question, there is a :headers
option to access each value by the headers.
The #read
method will slurp the entire file:
CSV.read(CSV_FILE_PATH, :headers => true).each do |line|
puts line['Ticker']
end
The #foreach
method is the intended primary interface for reading:
CSV.foreach(CSV_FILE_PATH, :headers => true) do |line|
puts line['Ticker']
end
Both methods will output:
EUR.USD-IDEALPRO-CASH
EUR.USD-IDEALPRO-CASH
See http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV.html.