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

verfi_2.9.0.0.1.0.source-code.show.scala Maven / Gradle / Ivy

There is a newer version: 0.1.2
Show newest version
package semverfi

trait Show[T <: SemVersion] {
  def show(v: T): String
}

object Show {
  implicit object ShowNormal extends Show[NormalVersion] {
    def show(v: NormalVersion) = "%d.%d.%d" format(
      v.major, v.minor, v.patch
    )
  }
  implicit object ShowPreRelease extends Show[PreReleaseVersion] {
    def show(v: PreReleaseVersion) = "%d.%d.%d-%s" format(
      v.major, v.minor, v.patch, v.classifier.mkString(".")
    )
  }
  implicit object ShowBuild extends Show[BuildVersion] {
    def show(v: BuildVersion) = "%d.%d.%d%s+%s" format(
      v.major, v.minor, v.patch,
      v.classifier match {
        case Nil => ""
        case cs => cs.mkString("-", ".", "")
      },
      v.build.mkString(".")
    )
  }
  implicit object ShowInvalid extends Show[Invalid] {
    def show(v: Invalid) = v match {
      case Invalid(raw) => "invalid: %s" format raw
    }
  }

  def apply[T <: SemVersion: Show](v: T) =
    implicitly[Show[T]].show(v)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy