struct ShortVersion
- ShortVersion
- Struct
- Value
- Object
Overview
Conforms to Short Versioning
Similar to Semantic Versioning but only with major and minor version numbers.
Included Modules
- Comparable(SemanticVersion)
- Comparable(ShortVersion)
Defined in:
short_version.crConstructors
-
.new(major : Int, minor : Int)
Creates a new
ShortVersion
instance with the given major and minor version. -
.parse(version : String) : self
Parses a
ShortVersion
from the given short version string. -
.parse(version : SemanticVersion) : self
Parses a
ShortVersion
from the givenSemanticVersion
.
Instance Method Summary
-
#<=>(other : self) : Int32
The comparison operator with self.
-
#<=>(other : SemanticVersion) : Int32
The comparison operator with SemanticVersion.
-
#bump_major
Returns a copy of the current version with a major bump.
-
#bump_minor
Returns a copy of the current version with a minor bump.
-
#copy_with(major : Int32 = @major, minor : Int32 = @minor)
Returns a new
ShortVersion
created with the specified parts. -
#major : Int32
The major version of this short version
-
#minor : Int32
The minor version of this short version
-
#to_s(io : IO) : Nil
Returns the string representation of this short version
-
#to_semver(patch : Int = 0) : SemanticVersion
Returns the
SemanticVersion
representation of this short version
Constructor Detail
Creates a new ShortVersion
instance with the given major and minor
version.
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.
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)
Instance Method Detail
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
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
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)
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)
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)
Returns the string representation of this short version
require "short_version"
shortver = ShortVersion.parse("0.27")
shortver.to_s # => "0.27"
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, ...)