verfi_2.9.0.0.1.0.source-code.show.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of semverfi_2.9.0 Show documentation
Show all versions of semverfi_2.9.0 Show documentation
Always Faithful, always loyal semantic versions
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)
}