Class: RubyLLM::Registry::Version
- Inherits:
-
Object
- Object
- RubyLLM::Registry::Version
- 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
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
-
#prerelease ⇒ Object
readonly
Returns the value of attribute prerelease.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(major:, minor:, patch:, prerelease: nil) ⇒ Version
constructor
A new instance of Version.
- #inspect ⇒ Object
- #release_rank ⇒ Object
- #stable? ⇒ Boolean
- #to_s ⇒ Object
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
#major ⇒ Object (readonly)
Returns the value of attribute major.
10 11 12 |
# File 'lib/ruby_llm/registry/semver.rb', line 10 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
10 11 12 |
# File 'lib/ruby_llm/registry/semver.rb', line 10 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
10 11 12 |
# File 'lib/ruby_llm/registry/semver.rb', line 10 def patch @patch end |
#prerelease ⇒ Object (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 |
#inspect ⇒ Object
50 51 52 |
# File 'lib/ruby_llm/registry/semver.rb', line 50 def inspect "#<#{self.class.name} #{self}>" end |
#release_rank ⇒ Object
37 38 39 |
# File 'lib/ruby_llm/registry/semver.rb', line 37 def release_rank prerelease.nil? ? 1 : 0 end |
#stable? ⇒ Boolean
41 42 43 |
# File 'lib/ruby_llm/registry/semver.rb', line 41 def stable? prerelease.nil? end |
#to_s ⇒ Object
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 |