X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=task-reporter.git;a=blobdiff_plain;f=src%2Fmain%2Fscala%2Fjp%2Fymir%2FtaskReporter%2Fcore%2FLTSV.scala;fp=src%2Fmain%2Fscala%2Fjp%2Fymir%2FtaskReporter%2Fcore%2FLTSV.scala;h=5550c549af706af6c2dec17f11243b7584e1ba95;hp=0000000000000000000000000000000000000000;hb=3b81fbc877a2b1e346d8f09cb215661cfe2dde30;hpb=b098d253574a32e3c77952987033f9e5ce35c572 diff --git a/src/main/scala/jp/ymir/taskReporter/core/LTSV.scala b/src/main/scala/jp/ymir/taskReporter/core/LTSV.scala new file mode 100644 index 0000000..5550c54 --- /dev/null +++ b/src/main/scala/jp/ymir/taskReporter/core/LTSV.scala @@ -0,0 +1,27 @@ +package jp.ymir.taskReporter.core +import scala.collection.immutable.StringLike +import jp.ymir.taskReporter.core._ + +trait LTSVFunctions { + import TSV._ + + def decode[A: FromRecord](tsv: StringLike[_]): Seq[A] = { + def toTuple(col: String): (Symbol, Field) = { + val pattern = """^([^:]+):(.*)$""".r + col match { + case pattern(label, value) => + (Symbol(label), Field(value)) + } + } + val lines = tsv.split('\n').filter(!_.isEmpty) + val records = lines.map(line => Record(line.split('\t').map(toTuple).toMap)) + return records.map { r => + runParser(r.parseRecord[A]) match { + case Right(a) => a + case Left(e) => throw new DecodeFailedException(e) + } + } + } +} + +object LTSV extends TSVTypes with LTSVFunctions