|
@@ -3,12 +3,12 @@ package models
|
|
|
class ConversionException(from: Unit, to: Unit) extends
|
|
class ConversionException(from: Unit, to: Unit) extends
|
|
|
RuntimeException(s"Cannot convert from $from to $to.", null)
|
|
RuntimeException(s"Cannot convert from $from to $to.", null)
|
|
|
|
|
|
|
|
-sealed trait Unit {
|
|
|
|
|
- def productPrefix: String
|
|
|
|
|
- protected def conversion: Float
|
|
|
|
|
- def name: String = this.productPrefix.split("\\.").last
|
|
|
|
|
- protected def abreviation: String
|
|
|
|
|
- def measure: Measure
|
|
|
|
|
|
|
+class Unit(
|
|
|
|
|
+ val name: String,
|
|
|
|
|
+ abreviation: String,
|
|
|
|
|
+ conversion: Float,
|
|
|
|
|
+ val measure: Measure
|
|
|
|
|
+) {
|
|
|
def convertToPrimary(v: Float): Float = v/conversion
|
|
def convertToPrimary(v: Float): Float = v/conversion
|
|
|
def convertFromPrimary(v: Float): Float = v*conversion
|
|
def convertFromPrimary(v: Float): Float = v*conversion
|
|
|
def convertTo(v: Float, other: Unit) = {
|
|
def convertTo(v: Float, other: Unit) = {
|
|
@@ -19,6 +19,7 @@ sealed trait Unit {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/*
|
|
|
case object Gram extends Unit
|
|
case object Gram extends Unit
|
|
|
{
|
|
{
|
|
|
protected val conversion: Float = 1f
|
|
protected val conversion: Float = 1f
|
|
@@ -95,3 +96,4 @@ case object Count extends Unit
|
|
|
val measure: Measure = Number
|
|
val measure: Measure = Number
|
|
|
val abreviation: String = ""
|
|
val abreviation: String = ""
|
|
|
}
|
|
}
|
|
|
|
|
+ */
|