aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/pdsuicommon/domain/FuzzyValue.scala
blob: b0ee436b3d93f13e2d5324ecacab9a34dac5905d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package xyz.driver.pdsuicommon.domain

import xyz.driver.pdsuicommon.logging._
import xyz.driver.pdsuicommon.utils.Utils

sealed trait FuzzyValue

object FuzzyValue {
  case object Yes   extends FuzzyValue
  case object No    extends FuzzyValue
  case object Maybe extends FuzzyValue

  private val yes   = "Yes"
  private val no    = "No"
  private val maybe = "Maybe"

  val All: Set[FuzzyValue] = {
    Set(Yes, No, Maybe)
  }

  def fromBoolean(x: Boolean): FuzzyValue = {
    if (x) Yes else No
  }

  implicit def toPhiString(x: FuzzyValue): PhiString = {
    Unsafe(Utils.getClassSimpleName(x.getClass))
  }


  val fromString: PartialFunction[String, FuzzyValue] = {
    case fuzzy => fuzzy.toLowerCase.capitalize match {
      case `yes`   => Yes
      case `no`    => No
      case `maybe` => Maybe
    }
  }

  def valueToString(x: FuzzyValue): String = x match {
    case Yes   => `yes`
    case No    => `no`
    case Maybe => `maybe`
  }
}