Class: ReleaseCeremony::Semver

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/release_ceremony/semver.rb

Overview

A strict X.Y.Z release version: no prereleases, no leading zeroes.

Constant Summary collapse

PATTERN =
/\A(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\z/
ERROR_MESSAGE =
'Version must use the X.Y.Z format'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Semver

Returns a new instance of Semver.



23
24
25
26
# File 'lib/release_ceremony/semver.rb', line 23

def initialize(value)
  @value = value
  @gem_version = Gem::Version.new(value)
end

Class Method Details

.parse(value) ⇒ Object

Raises:



14
15
16
17
18
# File 'lib/release_ceremony/semver.rb', line 14

def parse(value)
  raise Error, ERROR_MESSAGE unless value.is_a?(String) && PATTERN.match?(value)

  new(value)
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
31
32
# File 'lib/release_ceremony/semver.rb', line 28

def <=>(other)
  return unless other.is_a?(self.class)

  gem_version <=> other.gem_version
end

#tagObject



38
39
40
# File 'lib/release_ceremony/semver.rb', line 38

def tag
  "v#{value}"
end

#to_sObject



34
35
36
# File 'lib/release_ceremony/semver.rb', line 34

def to_s
  value
end