]> gitweb @ CieloNegro.org - task-reporter.git/blob - src/main/scala/jp/ymir/taskReporter/core/Task.scala
new tsv
[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 case class Task(
7   date:                   Calendar,
8   ticketID:               Option[Int],
9   title:                  String,
10   expectedCompletionDate: Calendar,
11   deadline:               Option[Calendar],
12   status:                 Task.Status,
13   description:            Option[String]
14 )
15
16 object Task {
17   import TSV._
18
19   sealed abstract class Status
20   object Status {
21     case object DoingFine extends Status
22     case object Lagging extends Status
23     case object DeadlineChanged extends Status
24     case object Completed extends Status
25   }
26
27   implicit def CalendarFromField = new FromField[Calendar] {
28     val pattern = """^(\d{4})/(\d{2})/(\d{2})$""".r
29
30     def parseField(f: Field): Calendar = {
31       f match {
32         case pattern(year, month, day) =>
33           new GregorianCalendar(year.toInt, month.toInt, day.toInt)
34       }
35     }
36   }
37
38   implicit def StatusFromField = new FromField[Status] {
39     def parseField(f: Field): Status = f match {
40       case "順調"     => Status.DoingFine
41       case "遅延"     => Status.Lagging
42       case "期限変更" => Status.DeadlineChanged
43       case "完了"     => Status.Completed
44     }
45   }
46
47   implicit def TaskFromRecord = new FromRecord[Task] {
48     def parseRecord(r: Record): Task = {
49       return Task(
50         date                   = parseField[Calendar](r('報告日)),
51         ticketID               = parseField[Option[Int]](r('チケットID)),
52         title                  = parseField[String](r('作業名)),
53         expectedCompletionDate = parseField[Calendar](r('作業完了予定年月日)),
54         deadline               = parseField[Option[Calendar]](r('タスク期限)),
55         status                 = parseField[Status](r('状態)),
56         description            = parseField[Option[String]](r('説明))
57       )
58     }
59   }
60 }
61
62 /*
63 class Task(tsvLine: String) {
64   sealed abstract class Status
65   object Status {
66     case object NoProgress extends Status
67     case object DoingFine extends Status
68     case object Lagging extends Status
69     case object WillDelay extends Status
70     case object DeadlineChanged extends Status
71     case object Completed extends Status
72   }
73
74   class InvalidNumberOfColumnsException private(e: RuntimeException) extends RuntimeException(e) {
75     def this(msg: String) = this(new RuntimeException(msg))
76     def this(msg: String, cause: Throwable) = this(new RuntimeException(msg, cause))
77   }
78
79   private val cols = tsvLine.split("\\t")
80   if (cols.length != 7) {
81     throw new InvalidNumberOfColumnsException(tsvLine)
82   }
83
84   var date : Calendar = {
85     val pattern = """^(?:報告日:)?(\d{4})/(\d{2})/(\d{2})$""".r
86     cols(0) match {
87       case pattern(year, month, day) =>
88         new GregorianCalendar(year.toInt, month.toInt, day.toInt)
89     }
90   }
91
92   var ticketID : Int = {
93     val pattern = """^(?:チケットID:)?(\d+)$""".r
94     cols(1) match {
95       case pattern(id) => id.toInt
96     }
97   }
98
99   var title : String = {
100     val pattern = """^(?:作業名:)?(.*)$""".r
101     cols(2) match {
102       case pattern(title) => title
103     }
104   }
105
106   var tentativeDeadline : Option[Calendar] = {
107     val pattern = """^(?:仮期限:)?(\d{4})/(\d{2})/(\d{2})$""".r
108     cols(3) match {
109       case pattern(year, month, day) =>
110         Some(new GregorianCalendar(year.toInt, month.toInt, day.toInt))
111       case _ =>
112         None
113     }
114   }
115
116   var deadline : Option[Calendar] = {
117     val pattern = """^(?:期限:)?(\d{4})/(\d{2})/(\d{2})$""".r
118     cols(4) match {
119       case pattern(year, month, day) =>
120         Some(new GregorianCalendar(year.toInt, month.toInt, day.toInt))
121       case _ =>
122         None
123     }
124   }
125
126   var status : Status = {
127     val pattern = """^(?:状態:)?(.+)$""".r
128     cols(5) match {
129       case pattern(s) =>
130         s match {
131           case "未作業"   => Status.NoProgress
132           case "順調"     => Status.DoingFine
133           case "悪化"     => Status.Lagging
134           case "遅延"     => Status.WillDelay
135           case "期限変更" => Status.DeadlineChanged
136           case "完了"     => Status.Completed
137         }
138     }
139   }
140
141   var supplement : String = {
142     val pattern = """^(?:補足:)?(.*)$""".r
143     cols(6) match {
144       case pattern(title) => title
145     }
146   }
147 }
148  */