Forum: Ruby on Rails newbie wants to know..FasterCSV or just CSV?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
26ca684555abbdb44f01bd1e165e649b?d=identicon&s=25 vince (Guest)
on 2006-05-17 08:54
I'm trying to grab a CSV file from a user and let them upload it
directly to my database, but doing some minor checks on the data before
saving.  Which is the easier way to implement this? CSV or FasterCSV?  I
saw that perhaps there were some issues with FasterCSV and csv files
created from Mac versions of Excel.

Anyone have any experience with this and can recommend a newbie friendly
path?
91eb330fb36d1e03c856574dfb77d2bc?d=identicon&s=25 Thibaut Barrère (thbar)
on 2006-05-17 09:46
(Received via mailing list)
Hi Vince

to me FasterCSV is quite easy to understand and use (before picking up
one
of those two, I had a look at both APIs but found FasterCSV more
intuitive).

Using excel CSV files exported on one platform (say PC) then imported on
another (say Mac) will cause troubles (I had those problems just two
days
ago!). It seems that the exported data is not stored in UTF-8 but in
ANSI,
with platform-specific codepage.

hope this helps.

Thibaut
26ca684555abbdb44f01bd1e165e649b?d=identicon&s=25 Vince W. (vince)
on 2006-05-17 10:51
Thibaut Barrère wrote:

> to me FasterCSV is quite easy to understand and use (before picking up
> one
> of those two, I had a look at both APIs but found FasterCSV more
> intuitive).

It's just that documentation is a little sparse on using it.  Are there
examples anywhere for having somebody upload a csv and then saving the
contents to a database?  I'm trying to parse just four fields: title,
description, quantity, and price.

I saw a tip on rails.techno-weenie that uses migrations but couldn't
quite make sense of it.

> Using excel CSV files exported on one platform (say PC) then imported on
> another (say Mac) will cause troubles

The clients could be anything (mac, win, linux) but the server is linux.
Does that mean I'll have problems unless the csv is also exported from a
linux box?  Is that an issue with the regular csv library too?

Thanks in advance..
91eb330fb36d1e03c856574dfb77d2bc?d=identicon&s=25 Thibaut Barrère (thbar)
on 2006-05-17 11:28
(Received via mailing list)
> It's just that documentation is a little sparse on using it.  Are there
> examples anywhere for having somebody upload a csv and then saving the
> contents to a database?  I'm trying to parse just four fields: title,
> description, quantity, and price.

This library's documentation doesn't describe the file upload part of
course.

I'd suggest you write a unit test to play with the parsing part first,
using
sample CSV data, then deal with the upload thingy once you're done
('step by
step, ouuh baby' like they sing it).

If you can wait 8pm UTC+2 I'll post a sample of how to do that (I'm
working
on something similar).

The clients could be anything (mac, win, linux) but the server is linux.
> Does that mean I'll have problems unless the csv is also exported from a
> linux box?  Is that an issue with the regular csv library too?


I think you'll have the same issue with the regular csv. It's more a
behaviour of excel export and an issue with encoding and codepages than
something caused by the library.

cheers
26ca684555abbdb44f01bd1e165e649b?d=identicon&s=25 Vince W. (vince)
on 2006-05-17 13:10
>
> If you can wait 8pm UTC+2 I'll post a sample of how to do that (I'm
> working
> on something similar).

I can definitely wait.  Thanks very much!
Aaf9d67916c3c07e43a20e5e885f757b?d=identicon&s=25 Asa Hopkins (asa)
on 2006-05-17 19:55
I seem to recall that FasterCSV is GPL, while CSV is the same license as
Ruby (MIT?).  Repending on what you intend to do with your final
product, licensing choices may matter to you.

vince wrote:
> I'm trying to grab a CSV file from a user and let them upload it
> directly to my database, but doing some minor checks on the data before
> saving.  Which is the easier way to implement this? CSV or FasterCSV?  I
> saw that perhaps there were some issues with FasterCSV and csv files
> created from Mac versions of Excel.
>
> Anyone have any experience with this and can recommend a newbie friendly
> path?
91eb330fb36d1e03c856574dfb77d2bc?d=identicon&s=25 Thibaut Barrère (thbar)
on 2006-05-18 00:21
(Received via mailing list)
>
> I can definitely wait.  Thanks very much!
>

Hi

here's a sample of what I'm using - here if you don't have headers
defined
on the first line of the csv:

    FasterCSV.foreach(File.dirname(__FILE__)
+"/../fixtures/answers.csv",
      :col_sep => ';',
      :headers => %w(id label question_number next_question_number
message))
do |row|
      puts row["label"]
      ...
      end
    end

all the options are explained here : http://fastercsv.rubyforge.org/

Asa: FasterCSV is "distributed under the user's choice of the
GPL<http://www.gnu.org/copyleft/gpl.html>(see COPYING for details) or
the Ruby
software license <http://www.ruby-lang.org/en/LICENSE.txt> by James
Edward
Gray II.", see http://fastercsv.rubyforge.org/files/LICENSE.html for
details

cheers

Thibaut
This topic is locked and can not be replied to.