Project

General

Profile

Bug #12100 ยป fix_csv_converter_single_arg_proc.patch

mdaubert (Matthew Daubert), 02/22/2016 04:14 PM

View differences:

lib/csv.rb
fields.map.with_index do |field, index|
converters.each do |converter|
break if field.nil?
field = if converter.arity == 1 # straight field converter
field = if converter.arity.abs == 1 # straight field converter
converter[field]
else # FieldInfo converter
header = @use_headers && !headers ? @headers[index] : nil
test/csv/test_data_converters.rb
assert_equal(["Numbers", ":integer", "1", ":float", 3], @parser.shift)
end
def test_convert_with_custom_proc_one_arg
# define custom converter as a proc accepting one argument
assert_nothing_raised(Exception) { @parser.convert(&:upcase) }
# and use
assert_equal(["NUMBERS", ":INTEGER", "1", ":FLOAT", "3.015"], @parser.shift)
end
def test_convert_with_custom_code_using_field_info_header
@parser = CSV.new(@data, headers: %w{one two three four five})
    (1-1/1)