# struct SemanticVersion

- SemanticVersion
- Struct
- Value
- Object

##
Overview

Conforms to Semantic Versioning 2.0.0

See https://semver.org/ for more information.

##
Included Modules

- Comparable(SemanticVersion)

##
Defined in:

##
Constructors

- .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.

- #build : String?

  The build metadata of this semantic version

- #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) ==, >(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`

!=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other) ===, =~(other) =~, __crystal_pseudo_! : Bool __crystal_pseudo_!, __crystal_pseudo_as(type : Class) __crystal_pseudo_as, __crystal_pseudo_as?(type : Class) __crystal_pseudo_as?, __crystal_pseudo_is_a?(type : Class) : Bool __crystal_pseudo_is_a?, __crystal_pseudo_nil? : Bool __crystal_pseudo_nil?, __crystal_pseudo_responds_to?(name : Symbol) : Bool __crystal_pseudo_responds_to?, class class, dup dup, hash(hasher)
hash hash, inspect : String
inspect(io : IO) : Nil inspect, itself itself, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, 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 : String
to_s(io : IO) : Nil 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

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.

##
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

def build : String? #

The build metadata of this semantic version

def major : Int32 #

The major version of this semantic version

def minor : Int32 #

The minor version of this semantic version

def patch : Int32 #

The patch version of this semantic version

def prerelease : Prerelease #

The pre-release version of this semantic version

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"