|
|
@@ -32,22 +32,22 @@ sealed trait MeasureUnit {
|
|
|
case (MASS, VOLUME) => food.density match {
|
|
|
case Some(density) => VOLUME.defaultUnit
|
|
|
.convert(food, amount / density, to)
|
|
|
- case None => Failure(new IncompleteDataException("density"))
|
|
|
+ case None => Failure(new IncompleteDataException(food, "density"))
|
|
|
}
|
|
|
case (MASS, NUMBER) => food.massPerUnit match {
|
|
|
case Some(massPerUnit) => NUMBER.defaultUnit
|
|
|
.convert(food, amount / massPerUnit, to)
|
|
|
- case None => Failure(new IncompleteDataException("mass/unit"))
|
|
|
+ case None => Failure(new IncompleteDataException(food, "mass/unit"))
|
|
|
}
|
|
|
case (VOLUME, _) => food.density match {
|
|
|
case Some(density) => MASS.defaultUnit
|
|
|
.convert(food, amount * density, to)
|
|
|
- case None => Failure(new IncompleteDataException("density"))
|
|
|
+ case None => Failure(new IncompleteDataException(food, "density"))
|
|
|
}
|
|
|
case (NUMBER, _) => food.massPerUnit match {
|
|
|
case Some(massPerUnit) => MASS.defaultUnit.
|
|
|
convert(food, amount * massPerUnit, to)
|
|
|
- case None => Failure(new IncompleteDataException("mass/unit"))
|
|
|
+ case None => Failure(new IncompleteDataException(food, "mass/unit"))
|
|
|
}
|
|
|
}).map(_ * conversionRatio)
|
|
|
}
|
|
|
@@ -70,7 +70,9 @@ object MeasureUnit {
|
|
|
GallonUS,
|
|
|
// DryPintUS,
|
|
|
// DryQuartUS,
|
|
|
- Dozen
|
|
|
+ Dozen,
|
|
|
+ InCube,
|
|
|
+ CmCube
|
|
|
)
|
|
|
|
|
|
def fromString(str: String) = units.find(_.abr == str)
|
|
|
@@ -78,10 +80,8 @@ object MeasureUnit {
|
|
|
def apply(i: Int) = units(i)
|
|
|
|
|
|
private def matchDegree(haystack: String)(needle: String) = {
|
|
|
- val startsWithNeedle = s"$needle[^\\s]".r
|
|
|
- val containsNeedle = s"[^\\s]$needle[^\\s]".r
|
|
|
if (needle == haystack || haystack.startsWith(s"1 $needle") || haystack.startsWith(s"${needle}s")) Some(100000)
|
|
|
- if (needle.size > 1 && haystack.startsWith(s"${needle}")) Some(10000 - Math.abs(haystack.length - needle.length))
|
|
|
+ else if (needle.size > 1 && haystack.startsWith(s"${needle}")) Some(10000 - Math.abs(haystack.length - needle.length))
|
|
|
// else if (containsNeedle.findFirstIn(haystack).nonEmpty)
|
|
|
// Some(10000 - Math.abs(haystack.length - needle.length))
|
|
|
else None
|
|
|
@@ -235,6 +235,7 @@ object InCube extends MeasureUnit {
|
|
|
override val conversionRatio = 16.38706
|
|
|
override val name = "Cubic inch"
|
|
|
override val abr = "in^3"
|
|
|
+ override val altNames: Seq[String] = Seq("cubic in")
|
|
|
}
|
|
|
|
|
|
object FluidOunceUS extends MeasureUnit {
|