]> 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 DeadlineChanged 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   var 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   var ticketID : Int = {
36     val pattern = """^(?:チケットID:)?(\d+)$""".r
37     cols(1) match {
38       case pattern(id) => id.toInt
39     }
40   }
41
42   var title : String = {
43     val pattern = """^(?:作業名:)?(.*)$""".r
44     cols(2) match {
45       case pattern(title) => title
46     }
47   }
48
49   var tentativeDeadline : Option[Calendar] = {
50     val pattern = """^(?:仮期限:)?(\d{4})/(\d{2})/(\d{2})$""".r
51     cols(3) match {
52       case pattern(year, month, day) =>
53         Some(new GregorianCalendar(year.toInt, month.toInt, day.toInt))
54       case _ =>
55         None
56     }
57   }
58
59   var deadline : Option[Calendar] = {
60     val pattern = """^(?:期限:)?(\d{4})/(\d{2})/(\d{2})$""".r
61     cols(4) match {
62       case pattern(year, month, day) =>
63         Some(new GregorianCalendar(year.toInt, month.toInt, day.toInt))
64       case _ =>
65         None
66     }
67   }
68
69   var status : Status = {
70     val pattern = """^(?:状態:)?(.+)$""".r
71     cols(5) match {
72       case pattern(s) =>
73         s match {
74           case "未作業"   => Status.NoProgress
75           case "順調"     => Status.DoingFine
76           case "悪化"     => Status.Lagging
77           case "遅延"     => Status.WillDelay
78           case "期限変更" => Status.DeadlineChanged
79           case "完了"     => Status.Completed
80         }
81     }
82   }
83
84   var supplement : String = {
85     val pattern = """^(?:補足:)?(.*)$""".r
86     cols(6) match {
87       case pattern(title) => title
88     }
89   }
90 }