]> gitweb @ CieloNegro.org - task-reporter.git/blob - src/main/scala/jp/ymir/taskReporter/core/Task.scala
wip
[task-reporter.git] / src / main / scala / jp / ymir / taskReporter / core / Task.scala
1 package jp.ymir.taskReporter.core
2 import java.util.Calendar
3 import java.util.GregorianCalendar
4 import scala.util.matching.Regex
5
6 class Task(tsvLine: String) {
7   sealed abstract class Status
8   object Status {
9     case object NoProgress extends Status
10     case object DoingFine extends Status
11     case object Lagging extends Status
12     case object WillDelay extends Status
13     case object DeadlinePostponed extends Status
14     case object Completed extends Status
15   }
16
17   class InvalidNumberOfColumnsException private(e: RuntimeException) extends RuntimeException(e) {
18     def this(msg: String) = this(new RuntimeException(msg))
19     def this(msg: String, cause: Throwable) = this(new RuntimeException(msg, cause))
20   }
21
22   private val cols = tsvLine.split("\\t")
23   if (cols.length != 7) {
24     throw new InvalidNumberOfColumnsException(tsvLine)
25   }
26
27   val date : Calendar = {
28     val pattern = """^(?:報告日:)?(\d{4})/(\d{2})/(\d{2})$""".r
29     cols(0) match {
30       case pattern(year, month, day) =>
31         new GregorianCalendar(year.toInt, month.toInt, day.toInt)
32     }
33   }
34
35   val ticketID : Int = {
36     val pattern = """^(?:チケットID:)?(\d+)$""".r
37     cols(1) match {
38       case pattern(id) => id.toInt
39     }
40   }
41
42   val title : String = {
43     val pattern = """^(?:作業名:)?(.*)$""".r
44     cols(1) match {
45       case pattern(title) => title
46     }
47   }
48 }