banno / banno-csv

Typesafe CSV parsing

GitHub

banno-csv

Typesafe CSV parsing in scala.

Usage

  1. Read file in as a String
  2. Parse
val csvFileAsString = "..."
CSVParser.parseCSVFile(csvFileAsString)

// parsed.rows must contain(exactly(ParsedCSVRow(Map(("First Name" -> "Frank"),
//                                                   ("Last Name" -> "Bob"),
//                                                   ("Email" -> "frank.bob@banno.com")))))

You can use Banno-csv to convert a CSV string to a case class.

  1. Create your case class that will represent a CSV row
  2. Add an implicit Formats in your case class' companion object.
  3. Then use the CSVParser object's .parseCSVTo function to convert it.
case class Person(first: String, last: String, age: Int)
object Person {
  implicit val personFormat = CSVProductFormats.productFormat3("First Name", "Last Name", "Age")(Person.apply)(Person.unapply)
}

CSVParser.parseCSVTo[Person]("csv as string")

//Success(Seq(Person("Frank", "Bob", "45"), ...))

Get banno-csv

In your build.sbt

resolvers += "bintray-banno-oss-releases" at "http://dl.bintray.com/banno/oss"

libraryDependencies ++= Seq(
  "com.banno" %% "banno-csv" % "1.1.0"
)

Contributing

Fork away, commit, and send a pull request. Make sure that the tests pass before you submit your pull request.