Module: Pairwise::Csv

Defined in:
lib/pairwise/input_file.rb

Instance Method Summary collapse

Instance Method Details

#load_and_parseObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/pairwise/input_file.rb', line 46

def load_and_parse
  require 'csv'

  csv_data = CSV.read @filename
  headers = csv_data.shift.map {|head| head.to_s.strip }
  string_data = csv_data.map {|row| row.map {|cell| cell.to_s.strip } }

  inputs = Hash.new {|h,k| h[k] = []}

  string_data.each do |row|
    row.each_with_index { |value, index| inputs[headers[index]] << value }
  end

  inputs
end