#!/usr/bin/ruby ROWSEPARATOR = "|" FILENAME = "coordinate" f = File.open(FILENAME + ".yml","w") f.write(""); f.close File.open(FILENAME + ".csv","r"){ |file| first = true attributes = Array.new rowcount = 0 trigger = 0 n = 0 file.each{ |row| row = row.strip.chomp if first attributes = row.split(ROWSEPARATOR) first = false else rowyml = Hash.new("") eles = row.split(ROWSEPARATOR) eles.each_index{ |id| rowyml[attributes[id]] += ( rowyml[attributes[id]] == "" ? "" : " " ) + eles[id] unless ( attributes[id] == "" ) } File.open(FILENAME + n.to_s + ".yml","a+"){ |file| file.write("row" + rowcount.to_s + ":\n") rowyml.each{ |att,value| file.write(" " + (att + ":").ljust(25," ") + value + "\n") unless (value == "" or att == "") } file.write("\n") } end rowcount += 1 trigger += 1 if trigger > 1000 n += 1 trigger = 0 end } }