Created
March 28, 2016 19:55
-
-
Save thorntonrose/46f9ae945907912aa2c0 to your computer and use it in GitHub Desktop.
Class that represents a CSV (comma separated values) document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CsvDoc { | |
def doc = [] | |
def setHeader(titles) { | |
doc = [ toCsv(titles) ] + doc | |
} | |
def addRow(values) { | |
doc << toCsv(values) | |
} | |
def toCsv(list) { | |
list.collect { it instanceof Number ? it : "\"$it\"" }.join(",") | |
} | |
public String toString() { | |
doc.join("\n") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment