All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.norbitltd.spoiwo.model.Height.scala Maven / Gradle / Ivy

There is a newer version: 1.4.1
Show newest version
package com.norbitltd.spoiwo.model

object HeightUnit {
  lazy val Point = HeightUnit("Point")
  lazy val Unit = HeightUnit("Unit")
}

case class HeightUnit private (value: String) {
  override def toString: String = value
}

object Height {

  private[model] val Undefined = new Height(-1, HeightUnit.Point)

  implicit class HeightEnrichment(value: Int) {
    def points = new Height(value, HeightUnit.Point)
    def unitsOfHeight = new Height(value, HeightUnit.Unit)
  }
}

class Height(measureValue: Int, measureUnit: HeightUnit) {

  private val heightInUnits = measureUnit match {
    case HeightUnit.Point => measureValue * 20
    case HeightUnit.Unit  => measureValue
    case _ =>
      throw new IllegalArgumentException(s"Unable to convert Height Unit = $measureUnit to XLSX - unsupported enum!")
  }

  def toUnits: Int = heightInUnits

  def toPoints: Short = (heightInUnits / 20).toShort

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy