W3cubDocs

/Crystal 0.31

struct SemanticVersion

Overview

Conforms to Semantic Versioning 2.0.0

See https://semver.org/ for more information.

Included Modules

Defined in:

semantic_version.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(major : Int, minor : Int, patch : Int, prerelease : String | Prerelease | Nil = nil, build : String? = nil)Source

Creates a new SemanticVersion instance with the given major, minor, and patch versions and optionally build and pre-release version

Raises ArgumentError if prerelease is invalid pre-release version

def self.parse(str : String) : selfSource

Parses a SemanticVersion from the given semantic version string

require "semantic_version"

semver = SemanticVersion.parse("2.61.4")
semver # => #<SemanticVersion:0x55b3667c9e70 @major=2, @minor=61, @patch=4, ... >

Raises ArgumentError if str is not a semantic version.

Instance Method Detail

def <=>(other : self) : Int32Source

The comparison operator.

Returns -1, 0 or 1 depending on whether self's version is lower than other's, equal to other's version or greater than other's version.

require "semantic_version"

semver1 = SemanticVersion.new(1, 0, 0)
semver2 = SemanticVersion.new(2, 0, 0)

semver1 <=> semver2 # => -1
semver2 <=> semver2 # => 0
semver2 <=> semver1 # => 1

def build : String?Source

The build metadata of this semantic version

def major : Int32Source

The major version of this semantic version

def minor : Int32Source

The minor version of this semantic version

def patch : Int32Source

The patch version of this semantic version

def prerelease : PrereleaseSource

The pre-release version of this semantic version

def to_s(io : IO) : NilSource

Returns the string representation of this semantic version

require "semantic_version"

semver = SemanticVersion.parse("0.27.1")
semver.to_s # => "0.27.1"

© 2012–2019 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.31.1/SemanticVersion.html