-
-
Save pditommaso/8463735 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@Grab('com.xlson.groovycsv:groovycsv:1.0') | |
import com.xlson.groovycsv.CsvParser | |
// a normally parsed csv can only be searched through ONCE | |
// this is used to create a "re-searchable" object (List of Maps) | |
List<Map> csv2List( String filePath, boolean shouldTrim = true ) { | |
new File( filePath ).withReader { r -> | |
new CsvParser().parse( r ).with { csv -> | |
return csv.collect { line -> | |
line.columns.collectEntries { c, v -> | |
[ c, (shouldTrim ? line[ c ].trim() : line[ c ]) ] | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment