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

Instance methods inherited from module Comparable(SemanticVersion)

<(other : T) <, <=(other : T) <=, <=>(other : T) <=>, ==(other : T) ==, >(other : T) >, >=(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) : 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)
to_json
to_json
, to_pretty_json(indent : String = " ")
to_pretty_json(io : IO, indent : String = " ")
to_pretty_json
, to_s(io : IO) : Nil
to_s : String
to_s
, to_yaml(io : IO)
to_yaml
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) #

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


[View source]
def self.parse(str : String) : self #

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.


[View source]

Instance Method Detail

def <=>(other : self) : Int32 #

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

[View source]
def ==(other : self) #

def build : String? #

The build metadata of this semantic version


[View source]
def hash(hasher) #
Description copied from struct Struct

See Object#hash(hasher)


def major : Int32 #

The major version of this semantic version


[View source]
def minor : Int32 #

The minor version of this semantic version


[View source]
def patch : Int32 #

The patch version of this semantic version


[View source]
def prerelease : Prerelease #

The pre-release version of this semantic version


[View source]
def to_s(io : IO) : Nil #

Returns the string representation of this semantic version

require "semantic_version"

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

[View source]