Created
January 30, 2015 12:24
-
-
Save mgosk/28e4246c792cc57cc34b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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