struct ShortVersion

Overview

Conforms to Short Versioning

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

Included Modules

Defined in:

short_version.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(major : Int, minor : Int) #

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


[View source]
def self.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.


[View source]
def self.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)

[View source]

Instance Method Detail

def <=>(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

[View source]
def <=>(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

[View source]
def 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)

[View source]
def 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)

[View source]
def 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)

[View source]
def major : Int32 #

The major version of this short version


[View source]
def minor : Int32 #

The minor version of this short version


[View source]
def 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"

[View source]
def 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, ...)

[View source]