Class: Capsium::Package::Version
- Inherits:
-
Object
- Object
- Capsium::Package::Version
- Includes:
- Comparable
- Defined in:
- lib/capsium/package/version.rb,
sig/capsium/package/version.rbs
Overview
A semantic version (MAJOR.MINOR.PATCH[+build]) with semver precedence ordering.
Constant Summary collapse
- PATTERN =
/\A(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?\z/
Instance Attribute Summary collapse
-
#major ⇒ Integer
readonly
Returns the value of attribute major.
-
#minor ⇒ Integer
readonly
Returns the value of attribute minor.
-
#patch ⇒ Integer
readonly
Returns the value of attribute patch.
-
#prerelease ⇒ String?
readonly
Returns the value of attribute prerelease.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Integer
-
#initialize(major, minor, patch, prerelease = nil) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ String
Constructor Details
#initialize(major, minor, patch, prerelease = nil) ⇒ Version
Returns a new instance of Version.
22 23 24 25 26 27 |
# File 'lib/capsium/package/version.rb', line 22 def initialize(major, minor, patch, prerelease = nil) @major = major @minor = minor @patch = patch @prerelease = prerelease end |
Instance Attribute Details
#major ⇒ Integer (readonly)
Returns the value of attribute major.
13 14 15 |
# File 'lib/capsium/package/version.rb', line 13 def major @major end |
#minor ⇒ Integer (readonly)
Returns the value of attribute minor.
13 14 15 |
# File 'lib/capsium/package/version.rb', line 13 def minor @minor end |
#patch ⇒ Integer (readonly)
Returns the value of attribute patch.
13 14 15 |
# File 'lib/capsium/package/version.rb', line 13 def patch @patch end |
#prerelease ⇒ String? (readonly)
Returns the value of attribute prerelease.
13 14 15 |
# File 'lib/capsium/package/version.rb', line 13 def prerelease @prerelease end |
Class Method Details
Instance Method Details
#<=>(other) ⇒ Integer
29 30 31 32 33 34 |
# File 'lib/capsium/package/version.rb', line 29 def <=>(other) core = [major, minor, patch] <=> [other.major, other.minor, other.patch] return core unless core.zero? compare_prerelease(other) end |
#to_s ⇒ String
36 37 38 |
# File 'lib/capsium/package/version.rb', line 36 def to_s "#{major}.#{minor}.#{patch}#{"-#{prerelease}" if prerelease}" end |