Skip to content

Instantly share code, notes, and snippets.

@mgosk
Created January 30, 2015 12:24
Show Gist options
  • Save mgosk/28e4246c792cc57cc34b to your computer and use it in GitHub Desktop.
Save mgosk/28e4246c792cc57cc34b to your computer and use it in GitHub Desktop.
kage com.iterators.registries.types
import com.iterators.config.Unicorn.driver.simple._
sealed trait VatRate
case object VatRate23 extends VatRate
case object VatRate8 extends VatRate
case object VatRate5 extends VatRate
case object VatRate0 extends VatRate
case object VatRateEx extends VatRate //exempt - zwolniony
case object VatRateNS extends VatRate //Is Not Subject - nie podlega
object VatRate {
def mapping: Map[VatRate, String] = Map(VatRate23 -> "23%", VatRate8 -> "8%", VatRate5 -> "5%", VatRate0 -> "0%", VatRateEx -> "zw.", VatRateNS -> "np.")
def reverseMapping = mapping.map(_.swap)
def apply(s: String): VatRate = {
reverseMapping.getOrElse(s, throw new IllegalArgumentException(s"Registry state should be one of ${reverseMapping.keys.mkString(", ")}"))
}
def toString(vr: VatRate): String = {
mapping.getOrElse(vr, throw new IllegalArgumentException(s"Registry state should be one of ${mapping.keys.mkString(", ")}"))
}
implicit val vatRate = MappedColumnType.base[VatRate, String](
{ vr => toString(vr)},
{ s => apply(s)}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment