How do i skip over the first three rows instead of the only the first in FasterCSV

Matt Elhotiby picture Matt Elhotiby · Sep 7, 2011 · Viewed 7.9k times · Source

I am using FasterCSV and i am looping with a foreach like this

FasterCSV.foreach("#{Rails.public_path}/uploads/transfer.csv", :encoding => 'u', :headers => :first_row) do |row|

but the problem is my csv has the first 3 lines as the headers...any way to make fasterCSV skip the first three rows rather then only the first??

Answer

Mladen Jablanović picture Mladen Jablanović · Sep 7, 2011

Not sure about FasterCSV, but in Ruby 1.9 standard CSV library (which is made from FasterCSV), I can do something like:

c = CSV.open '/path/to/my.csv'
c.drop(3).each do |row|
  # do whatever with row
end