struct

ShortVersion

Inherits Comparable < Comparable < Struct < Value < Object

Conforms to Short Versioning

Similar to Semantic Versioning but only with major and minor version numbers.

Constructors

new(major : Int, minor : Int)

Creates a new ShortVersion instance with the given major and minor version.

Source
parse(version : String) : self

Parses a ShortVersion from the given short version string.

require "short_version""

shortver = ShortVersion.parse("2.61")
shortver # => ShortVersion(@major=2, @minor=61)

Raises ArgumentError if str is not a short version.

Source
parse(version : SemanticVersion) : self

Parses a ShortVersion from the given SemanticVersion.

require "short_version""

semver = SemanticVersion.parse("2.61.9")
shortver = ShortVersion.parse(semver)
shortver # => ShortVersion(@major=2, @minor=61)
Source

Instance methods

<=>(other : self) : Int32

The comparison operator with self.

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 "short_version"

ShortVersion.parse("1.0") <=> ShortVersion.parse("2.0") # => -1
ShortVersion.parse("1.0") <=> ShortVersion.parse("1.0") # => 0
ShortVersion.parse("2.0") <=> ShortVersion.parse("1.0") # => 1
Source
<=>(other : SemanticVersion) : Int32

The comparison operator with SemanticVersion.

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 "short_version"

ShortVersion.parse("1.0") <=> SemanticVersion.parse("2.0.0") # => -1
ShortVersion.parse("1.0") <=> SemanticVersion.parse("1.0.0") # => 0
ShortVersion.parse("1.0") <=> SemanticVersion.parse("0.1.0") # => 1
Source
bump_major

Returns a copy of the current version with a major bump.

require "short_version"

shortver = ShortVersion.parse("1.1")
shortver.bump_major # => ShortVersion(@major=2, @minor=0)
Source
bump_minor

Returns a copy of the current version with a minor bump.

require "short_version"

shortver = ShortVersion.parse("1.1")
shortver.bump_minor # => ShortVersion(@major=1, @minor=2)
Source
copy_with(major : Int32 = @major, minor : Int32 = @minor)

Returns a new ShortVersion created with the specified parts. The default for each part is its current value.

require "short_version"

current_version = ShortVersion.parse("1.1")
current_version.copy_with(minor: 2) # => ShortVersion(@major=1, @minor=2)
Source
major

The major version of this short version

Source
minor

The minor version of this short version

Source
to_s(io : IO) : Nil

Returns the string representation of this short version

require "short_version"

shortver = ShortVersion.parse("0.27")
shortver.to_s # => "0.27"
Source
to_semver(patch : Int = 0) : SemanticVersion

Returns the SemanticVersion representation of this short version

require "short_version"

shortver = ShortVersion.parse("0.27")
shortver.to_semver    # => SemanticVersion(@major=0, @minor=27, @patch=0, ...)
shortver.to_semver(1) # => SemanticVersion(@major=0, @minor=27, @patch=1, ...)
Source