Skip to content

Instantly share code, notes, and snippets.

@bwmcadams
Created August 26, 2010 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwmcadams/551881 to your computer and use it in GitHub Desktop.
Save bwmcadams/551881 to your computer and use it in GitHub Desktop.
val notHaveBlankRows = new Matcher[Iterable[Map[String, String]]] {
def apply(x: => Iterable[Map[String, String]]) = {
(x().forall(row => row.forall(kv => kv._2 != null && kv._2 != "" && kv._2 != None)),
"No blank rows contained in Iterable.",
"Blank rows (all values in row are either '', null or None) found in Iterable.")
}
}
@bwmcadams
Copy link
Author

def apply(filename: String, code: String): Iterable[Map[String, String]] = {
val tree = apply(code)
if (filename.toUpperCase.endsWith("XLS")) {
ExcelFile(filename, tree).toMapping
} else if (filename.toUpperCase.endsWith("CSV")) {
CSVFile(filename, tree).iterator
} else {
throw new IllegalArgumentException("Don't know how to parse this file extension (%s)".format(filename))
}
}.filter(row => row.forall(kv => kv._2 != null && kv._2 != "" && kv._2 != None))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment