lib/rake/data/dsl.rb
def file_loop( name, source )
      task name => source do
        if source =~ /.csv$/
          first_row = nil
          CSV.open( source ).each do |line|
            first_row ||= line
            values = Hash.new do |h,k|
              idx = first_row.index(k)
              if !idx
                raise "Couldn't find column named #{k}"
              end
              h[k] = line[idx]
            end
            yield line, values, first_row
          end
        else
          File.readlines( source ).each do |line|
            yield line
          end
        end
      end
    end
# Loop over a file and yield the block for each line
# If name ends with .csv, parse the csv and yield each line
Loop over a file and yield the block for each line
If name ends with .csv, parse the csv and yield each line
Loop over a file and yield the block for each line If name ends with . csv parse the csv and yield each line
def file_loop( name, source )
      task name => source do
        if source =~ /.csv$/
          first_row = nil
          CSV.open( source ).each do |line|
            first_row ||= line
            values = Hash.new do |h,k|
              idx = first_row.index(k)
              if !idx
                raise "Couldn't find column named #{k}"
              end
              h[k] = line[idx]
            end
            yield line, values, first_row
          end
        else
          File.readlines( source ).each do |line|
            yield line
          end
        end
      end
    end
def file_loop ( name , source ) task name => source do if source =~ / .csv$ / first_row = nil CSV . open ( source ) . each do | line | first_row ||= line values = Hash . new do | h , k | idx = first_row . index ( k ) if ! idx raise "Couldn't find column named #{k}" end h [ k ] = line [ idx ] end yield line , values , first_row end else File . readlines ( source ) . each do | line | yield line end end end end
Loop over a file and yield the block for each line
If name ends with .csv, parse the csv and yield each line
Loop over a file and yield the block for each line If name ends with . csv parse the csv and yield each line
name
source