fastercsv error with ruby 1.9.2
I found the answer to my question
Its based on this post
What is Ruby 1.9 standard CSV library?
and as the solution i had to
require 'csv'
instead of
require 'fastercsv'
and change the FasterCSV to CSV
What is Ruby 1.9 standard CSV library?
Ruby 1.9 has adopted FasterCSV as its built-in CSV library. However, it's in the standard library rather than Ruby 1.9's core, so you need to manually require it in your application.
After adding a
require 'csv'
to your code, you can then do things such as
CSV.parse("this,is,my,data")
See Ruby 1.9's standard library CSV documentation for information on using the library.
rails 3 ruby 1.9.2 CSV already initialized constant .. warning
I ran into the same issue, after some digging I realized that I was requiring 'CSV' where I should have been requiring 'csv' it should be all lowercase.
Rails 3 Server Startup problem with fastercsv
Remove fasterCSV from your Gemfile in the application. Bundler is trying to require FasterCSV because you have it specified in the Gemfile.
fasterCSV for ruby 1.9.3?
As of Ruby 1.9.2 FasterCSV is already included as standard library's CSV. Just change references in your application from FasterCSV to CSV and it should work. Check out the docs and this new Railscast.
Reading in CSV files smaller than 10K from S3 with Ruby 1.9.2 p290
I'm going to guess that CSV.read
is being handed a StringIO when it wants a String. If so, then you should be able to stick a read
call in and switch to CSV.parse
to make everyone happy:
lines = CSV.parse(open(resource.csv(:original)).read)
open and return fastercsv object with headers
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.
Example Application of FasterCSV
The FasterCSV examples folder provides several examples.
PS. Please note that FasterCSV has nothing to do with Rails framework. Is a Ruby library.
Related Topics
Creating Spectral Heat Maps or Intensity Maps from Cdip Data Using Ruby
How Get Best Performance Rails Requests Parallel Sidekiq Worker
Generate Array of Numbers That Fit to a Probability Distribution in Ruby
Find Products Matching All Categories (Rails 3.1)
How to Remove the Zone from a Datetime Value
Another Way Instead of Escaping Regex Patterns
How to Deal with App_Key and App_Secret (Dropbox API)
Listing Directories at a Given Level in Amazon S3
Displaying a Polygon with Gmaps4Rails
How to Use Escape Characters in Strings
How to Run All Ruby Scripts with Warnings
Ruby Gems Won't Load Even Though Installed
Twitter 3-Legged Authorization in Ruby
Ruby Elegant Way to Return Min/Max If Value Outside Range
Multi Level Block Method Is Generating Issue
Better Way to Write "Matching Balanced Parenthesis" Program in Ruby
Open-Uri Returning Ascii-8Bit from Webpage Encoded in Iso-8859