Models classes from CSVs

I have 8 csv dumps that I receive nightly. I have to transform them
into XML and FTP them. So far I have been able to complete this task.
Now the requirements are to match some records up between csv dumps.

I did not want to load all the files into a database, as I only work
with each nights data. I thought I could convert the csv to a model
after parsing it. I am unable to find information on converting the CSV
to active record or an active-model (not sure either one of these ideas
are correct approach).

Any help/suggestions would be appreciated.

Thanks!

T. Sanders

On Oct 22, 2012, at 11:33 PM, Todd S. [email protected] wrote:

I have 8 csv dumps that I receive nightly. I have to transform them
into XML and FTP them. So far I have been able to complete this task.
Now the requirements are to match some records up between csv dumps.

I did not want to load all the files into a database, as I only work
with each nights data. I thought I could convert the csv to a model
after parsing it. I am unable to find information on converting the CSV
to active record or an active-model (not sure either one of these ideas
are correct approach).

ActiveRecord requires a database. Persisting data in an SQL-database is
the whole point of the library.

ActiveModel is an interface that generalises common tasks with
model-like data.
It works by giving you a general implementation in which you have to
fill out the
blanks. ActiveRecord one of such implementations. Writing a
fully-fledged
AM-implementation for a bit of CSV data might be a bit too much.

There are multiple approaches:

  1. Just use plain old ruby objects and than match them by arranging the
    corresponding
    objects in memory. Its a bit more legwork, but depending on your dataset
    size, it shouldn’t
    be too difficult.
  2. If the task is more complex, why not connect ActiveRecord, DataMapper
    or Sequel to an
    in-memory-SQLite database (“sqlite://:memory:”, afaik)? This gives you
    all the power of the
    corresponding lib, but without the headache of handling a DB server.

I hope this gives you a few pointers. Without knowing the actual tasks
and the size of those
files, its hard to make good suggestions.

Regards,
Florian

Florian,

I’m new to developing and your post really did help as far as a
direction. I had no idea SQLite had a memory option. That sounds like
a much cleaner way of doing it. I’ve only developed one small rails
app, and this is my first ruby only project. Try to use ruby as much as
possible now.

Thanks again!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs