Skip to content

Commit

Permalink
Adds static methods parseCsv to CsvParser to make static imports poss…
Browse files Browse the repository at this point in the history
…ible.
  • Loading branch information
xlson committed Aug 20, 2011
1 parent f99f05c commit 54f3f90
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/com/xlson/groovycsv/CsvParser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,29 @@ class CsvParser {
* detection is used.
*/
Integer autoDetectCharNumber = 1000


/**
* Parses a string as csv in the same way as CsvParser.parse(...).
*
* @param args
* @param csv
* @return
*/
static Iterator parseCsv(Map args = [:], String csv) {
new CsvParser().parse(args, csv)
}

/**
* Parses a reader as csv in the same way as CsvParser.parse(...).
*
* @param args
* @param csv
* @return
*/
static Iterator parseCsv(Map args = [:], Reader reader) {
new CsvParser().parse(args, reader)
}

/**
* Parses the csv supplied using the reader. See parse(Reader reader) for
* more information about usage.
Expand Down
13 changes: 13 additions & 0 deletions test/com/xlson/groovycsv/CsvParserSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,18 @@ abc,-4-'''
line[2] == '19'
}
def "CsvParser.parseCsv can be used statically."() {
when:
def csv = CsvParser.parseCsv(csvData)
then:
csv*.Letter == letterValues
where:
csvData | letterValues
testDataWithColumnNamesAnd2Rows | ['a', 'h']
new StringReader(testDataWithColumnNamesAnd2Rows) | ['a', 'h']
}
}

0 comments on commit 54f3f90

Please sign in to comment.