Skip to content

Instantly share code, notes, and snippets.

@thorntonrose
Created March 28, 2016 19:55
Show Gist options
  • Save thorntonrose/46f9ae945907912aa2c0 to your computer and use it in GitHub Desktop.
Save thorntonrose/46f9ae945907912aa2c0 to your computer and use it in GitHub Desktop.
Class that represents a CSV (comma separated values) document
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