Class: RubyLLM::Registry::Version

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

Constant Summary collapse

VERSION_PATTERN =
/\Av?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major:, minor:, patch:, prerelease: nil) ⇒ Version

Returns a new instance of Version.



24
25
26
27
28
29
# File 'lib/ruby_llm/registry/semver.rb', line 24

def initialize(major:, minor:, patch:, prerelease: nil)
  @major = major
  @minor = minor
  @patch = patch
  @prerelease = prerelease
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



10
11
12
# File 'lib/ruby_llm/registry/semver.rb', line 10

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



10
11
12
# File 'lib/ruby_llm/registry/semver.rb', line 10

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



10
11
12
# File 'lib/ruby_llm/registry/semver.rb', line 10

def patch
  @patch
end

#prereleaseObject (readonly)

Returns the value of attribute prerelease.



10
11
12
# File 'lib/ruby_llm/registry/semver.rb', line 10

def prerelease
  @prerelease
end

Class Method Details

.parse(value) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby_llm/registry/semver.rb', line 12

def self.parse(value)
  match = VERSION_PATTERN.match(value.to_s)
  raise InvalidVersionError, "Invalid semantic version: #{value.inspect}" unless match

  new(
    major: match[1].to_i,
    minor: match[2].to_i,
    patch: match[3].to_i,
    prerelease: match[4]
  )
end

Instance Method Details

#<=>(other) ⇒ Object



31
32
33
34
35
# File 'lib/ruby_llm/registry/semver.rb', line 31

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

  [major, minor, patch, release_rank, prerelease.to_s] <=> [other.major, other.minor, other.patch, other.release_rank, other.prerelease.to_s]
end

#inspectObject



50
51
52
# File 'lib/ruby_llm/registry/semver.rb', line 50

def inspect
  "#<#{self.class.name} #{self}>"
end

#release_rankObject



37
38
39
# File 'lib/ruby_llm/registry/semver.rb', line 37

def release_rank
  prerelease.nil? ? 1 : 0
end

#stable?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ruby_llm/registry/semver.rb', line 41

def stable?
  prerelease.nil?
end

#to_sObject



45
46
47
48
# File 'lib/ruby_llm/registry/semver.rb', line 45

def to_s
  base = "#{major}.#{minor}.#{patch}"
  prerelease.nil? ? base : "#{base}-#{prerelease}"
end