struct SemanticVersion
Overview
Conforms to Semantic Versioning 2.0.0
See https://semver.org/ for more information.
Included Modules
Defined in:
semantic_version.crConstructors
- .new(major : Int, minor : Int, patch : Int, prerelease : String | Prerelease | Nil = nil, build : String? = nil)
Creates a new
SemanticVersion
instance with the given major, minor, and patch versions and optionally build and pre-release version - .parse(str : String) : self
Parses a
SemanticVersion
from the given semantic version string
Instance Method Summary
- #<=>(other : self) : Int32
The comparison operator.
- #==(other : self)
- #build : String?
The build metadata of this semantic version
- #hash(hasher)
- #major : Int32
The major version of this semantic version
- #minor : Int32
The minor version of this semantic version
- #patch : Int32
The patch version of this semantic version
- #prerelease : Prerelease
The pre-release version of this semantic version
- #to_s(io : IO) : Nil
Returns the string representation of this semantic version
Instance methods inherited from module Comparable(SemanticVersion)
<, <=(other : T) <=, <=>(other : T) <=>, ==(other : T) ==, >(other : T) : Bool >, >=(other : T) >=, clamp(min, max)clamp(range : Range) clamp
Instance methods inherited from struct Struct
==(other) : Bool ==, hash(hasher) hash, inspect(io : IO) : Nil inspect, pretty_print(pp) : Nil pretty_print, to_s(io : IO) : Nil to_s Instance methods inherited from struct Value
==(other : JSON::Any)==(other : YAML::Any)
==(other) ==, dup dup
Instance methods inherited from class Object
! : Bool !, !=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)===(other : YAML::Any)
===(other) ===, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash hash, in?(collection : Object) : Bool
in?(*values : Object) : Bool in?, inspect(io : IO) : Nil
inspect : String inspect, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String to_json, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil to_pretty_json, to_s(io : IO) : Nil
to_s : String to_s, to_yaml(io : IO) : Nil
to_yaml : String to_yaml, try(&) try, unsafe_as(type : T.class) forall T unsafe_as
Class methods inherited from class Object
from_json(string_or_io, root : String)from_json(string_or_io) from_json, from_yaml(string_or_io : String | IO) from_yaml
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 ==(other : self)
def hash(hasher)
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–2021 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.2.1/SemanticVersion.html