Module: HashFromCsv
- Defined in:
- lib/HashFromCsv.rb
Instance Method Summary collapse
Instance Method Details
#parseCsvToHash(string) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/HashFromCsv.rb', line 4 def parseCsvToHash (string) result = Hash.new col_names = Array.new line_nb = 0 string.split("\n").each { |line| if line_nb == 0 col_names = line.split(';') line_nb += 1 else cols = line.split(';') data = Hash.new (0..cols.count-1).each { |i| data[col_names[i]] = cols[i] } result[cols[0]] = data line_nb += 1 end } result end |