def splitlines()
sraw = self.to_s
sraw = sraw.gsub(/\r\n/,"\n");
sraw.to_s.split("\n");
end
def dsvpretty(delim=';;')
sout = "";
asizes = [];
alines = self.to_s.splitlines();
alines.each{|currline|
currline.split(delim).each_with_index{|currfld,icc|
asizes[icc] = [asizes[icc].to_i,currfld.length].max()
}
}
alines.each{|currline|
next if currline.strip == ''
atemp = []
currline.split(delim).each_with_index{|currfld,icc|
atemp << currfld.spr("%-#{asizes[icc]}s")
}
sout += atemp.join(delim.hug(" "))
sout += "\n"
}
return sout;
end
Refactorings
No refactoring yet !
allow any character(s) as the delimiter, no escaping is used, instead we just require the user to specify a delimiter that she knows will not appear in the raw data, implemented as a String expando method, includes a 'splitlines' method as a separate function