lib/sycsvpro/mapper.rb
def execute
      File.open(outfile, 'w') do |out|
        File.new(infile, 'r').each_with_index do |line, index|
          result = row_filter.process(line, row: index)
          next if result.chomp.empty? or result.nil?
          result += ' ' if result =~ /;$/
          cols = result.split(';')
          @col_filter.each do |key|
            substitute = mapper[cols[key]]
            cols[key] = substitute if substitute
          end
          out.puts cols.join(';').strip
        end
      end
    end
def execute
      File.open(outfile, 'w') do |out|
        File.new(infile, 'r').each_with_index do |line, index|
          result = row_filter.process(line, row: index)
          next if result.chomp.empty? or result.nil?
          result += ' ' if result =~ /;$/
          cols = result.split(';')
          @col_filter.each do |key|
            substitute = mapper[cols[key]]
            cols[key] = substitute if substitute
          end
          out.puts cols.join(';').strip
        end
      end
    end
def execute File . open ( outfile , 'w' ) do | out | File . new ( infile , 'r' ) . each_with_index do | line , index | result = row_filter . process ( line , row : index ) next if result . chomp . empty? or result . nil? result += ' ' if result =~ / / cols = result . split ( ';' ) @col_filter . each do | key | substitute = mapper [ cols [ key ] ] cols [ key ] = substitute if substitute end out . puts cols . join ( ';' ) . strip end end end
Creates new mapper
 :call-seq:
   Sycsvpro::Mapper.new(infile: "in.csv",
                        outfile: "out.csv",
                        mapping: "mapping.csv",
                        rows:    "1,3-5",
                        cols:    "3,4-7"
                        df:      "%Y-%m-%d").execute

 infile:: File that contains columns to be mapped
 outfile:: File that contains the mapping result after execute
 mapping:: File that contains the mappings. Mappings are separated by ':'
 rows:: Rows to consider for mappings
 cols:: Columns that should be mapped
 df:: Date format for row filter if rows are filtered on date values
 Executes the mapper
Creates new mapper : call - seq : Sycsvpro :: Mapper . new ( infile : in . csv outfile : out . csv mapping : mapping . csv rows : 1 3 - 5 cols : 3 4 - 7 df : %Y - %m - %d ) . execute