Reduce columns to produce product keycodes
I would do something like this. It is untested and may have typos but it should give you some idea of how to break the logic up.  I would:


Express variable to what they mean
Use a class


Hope this helps

require 'CSV'

class CSVTranslator
  def self.write file_path, options={}
    new(file_path, options).translate
  end

  def initialize source_file, options={}
    @source_file = source_file
    @destination_file = options.fetch(:to) { "#{File.basename(source_file, '.csv')}_coded.csv" }
  end

  def translate
    CSV.open(destination_file, 'a+') do |out|
      out &lt;&lt; headers
      each_row { |row| out &lt;&lt; row }
    end
  end

  private

  attr_reader :source_file, :destination_file

  def headers
    %w(First Last Company Address address2 City State Zip Country phone_number email_address keycode)
  end

  def each_row 
    CSV.foreach(source_file, headers: true) do |line|
      yield code_line_by_product(line)
    end
  end

  def code_line_by_product(line)
    new_line = {}
    english_language = false
    keycode = ""

    line.each do |header, value|
      if header.include?('#')
        english_language ||= value.include?('English') 
        keycode = value.first if value.first != '1'
      else
        new_line[header] = value
      end
    end

    new_line['keycode'] = keycode unless english_language || keycode.blank?

    new_line
  end
end

CSVTranslator.write 'test.csv', to: 'test_coded.csv'