def thread_import(return_headers = false)
csv = []
CSV.foreach(option_csv_file || '/dev/stdin', {
:skip_blanks => true,
:headers => :first_row,
:return_headers => return_headers
}) do |line|
csv << line
end
lines_per_thread = csv.length / option_threads.to_i + 1
splits = []
option_threads.to_i.times do |current_thread|
start_index = ((current_thread) * lines_per_thread).to_i
finish_index = ((current_thread + 1) * lines_per_thread).to_i
finish_index = csv.length if finish_index > csv.length
if start_index <= finish_index
lines = csv[start_index...finish_index].clone
splits << Thread.new do
lines.each do |line|
if line[NAME][0] != '#'
yield line
end
end
end
end
end
splits.each do |thread|
thread.join
end
end