Bryan W. wrote:
I edited your code and just changed a couple lines:
http://pastie.org/807473
I changed this:
input_file_stream = File.open(input_filename, “r”)
To this:
input_file_stream = IO.readlines(input_filename)
Using IO.readlines will just read the entire contents of the file and
store
each line as an element in an array. You can then iterate through the
array
rather than using a while loop.
I changed your loop and changed the line where you split the lines of
the
csv file from this:
input_file_line = input_file_stream.gets.to_s.split(/,/)
To this:
input_file_line = line.split(/,/)
This should work, I obviously did not test it. Hopefully this will
point
you in the right direction.
Bryan
Thanks everyone for helping me out. I really appreciate your help.
As I said previously, the CSV file is not constant — no used as a
database-like file. Here’s an exemple of the data :
http://pastie.org/807687
Every single line begins by the same string. However, the first and the
last lines differ from each other. Also, the middle lines are also
different from the first.
That is why I read the first line as being the headline and then going
through a loop till EOF. I achieved this part. It’s working great the
way I did it. However, I would like my loop to stop on the string
“Total:” which is part of the last line only.
The reason why I need to stop on that particular word is that I will
have many of the first lines, middles lines and last lines for specific
people in the same file.
That is why I could not use MySQL to import the CSV file and that (I
think) using FasterCSV wouldn’t help that much either. I also want to
automate processes the more I can.
Hope this can help to help me Maybe I am not doing it the way I
should be. I have to mention that I’m new with Ruby but, I love it.
Have a good day everyone!
Felix