]> gitweb @ CieloNegro.org - task-reporter.git/blobdiff - src/main/scala/jp/ymir/taskReporter/core/Task.scala
wip
[task-reporter.git] / src / main / scala / jp / ymir / taskReporter / core / Task.scala
diff --git a/src/main/scala/jp/ymir/taskReporter/core/Task.scala b/src/main/scala/jp/ymir/taskReporter/core/Task.scala
new file mode 100644 (file)
index 0000000..ebc8693
--- /dev/null
@@ -0,0 +1,48 @@
+package jp.ymir.taskReporter.core
+import java.util.Calendar
+import java.util.GregorianCalendar
+import scala.util.matching.Regex
+
+class Task(tsvLine: String) {
+  sealed abstract class Status
+  object Status {
+    case object NoProgress extends Status
+    case object DoingFine extends Status
+    case object Lagging extends Status
+    case object WillDelay extends Status
+    case object DeadlinePostponed extends Status
+    case object Completed extends Status
+  }
+
+  class InvalidNumberOfColumnsException private(e: RuntimeException) extends RuntimeException(e) {
+    def this(msg: String) = this(new RuntimeException(msg))
+    def this(msg: String, cause: Throwable) = this(new RuntimeException(msg, cause))
+  }
+
+  private val cols = tsvLine.split("\\t")
+  if (cols.length != 7) {
+    throw new InvalidNumberOfColumnsException(tsvLine)
+  }
+
+  val date : Calendar = {
+    val pattern = """^(?:報告日:)?(\d{4})/(\d{2})/(\d{2})$""".r
+    cols(0) match {
+      case pattern(year, month, day) =>
+        new GregorianCalendar(year.toInt, month.toInt, day.toInt)
+    }
+  }
+
+  val ticketID : Int = {
+    val pattern = """^(?:チケットID:)?(\d+)$""".r
+    cols(1) match {
+      case pattern(id) => id.toInt
+    }
+  }
+
+  val title : String = {
+    val pattern = """^(?:作業名:)?(.*)$""".r
+    cols(1) match {
+      case pattern(title) => title
+    }
+  }
+}