Class: TTY::Link::SemanticVersion Private
- Inherits:
-
Object
- Object
- TTY::Link::SemanticVersion
- Includes:
- Comparable
- Defined in:
- lib/tty/link/semantic_version.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Responsible for comparing terminal release versions
Instance Attribute Summary collapse
-
#major ⇒ Integer
readonly
The major number.
-
#minor ⇒ Integer
readonly
The minor number.
-
#patch ⇒ Integer
readonly
The patch number.
Class Method Summary collapse
-
.from(*version, separator: VERSION_SEPARATOR) ⇒ TTY::Link::SemanticVersion
Create a SemanticVersion instance from a version value.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
Compare this semantic version with another object.
-
#hash ⇒ Integer
Generate hash value for this semantic version.
-
#initialize(major, minor, patch) ⇒ SemanticVersion
constructor
private
Create a SemanticVersion instance.
-
#inspect ⇒ String
Convert this semantic version to a string.
Constructor Details
#initialize(major, minor, patch) ⇒ SemanticVersion
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a TTY::Link::SemanticVersion instance
145 146 147 148 149 |
# File 'lib/tty/link/semantic_version.rb', line 145 def initialize(major, minor, patch) @major = major @minor = minor @patch = patch end |
Instance Attribute Details
#major ⇒ Integer (readonly)
The major number
110 111 112 |
# File 'lib/tty/link/semantic_version.rb', line 110 def major @major end |
#minor ⇒ Integer (readonly)
The minor number
120 121 122 |
# File 'lib/tty/link/semantic_version.rb', line 120 def minor @minor end |
#patch ⇒ Integer (readonly)
The patch number
130 131 132 |
# File 'lib/tty/link/semantic_version.rb', line 130 def patch @patch end |
Class Method Details
.from(*version, separator: VERSION_SEPARATOR) ⇒ TTY::Link::SemanticVersion
Create a TTY::Link::SemanticVersion instance from a version value
60 61 62 63 64 65 66 67 68 |
# File 'lib/tty/link/semantic_version.rb', line 60 def self.from(*version, separator: VERSION_SEPARATOR) major, minor, patch = if version.size == 1 && version[0].respond_to?(:split) convert_to_array(version[0], separator: separator) else version end new(major.to_i, minor.to_i, patch.to_i) end |
Instance Method Details
#<=>(other) ⇒ Integer?
Compare this semantic version with another object
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/tty/link/semantic_version.rb', line 167 def <=>(other) return unless other.is_a?(self.class) major_comparison = @major <=> other.major return major_comparison unless major_comparison.zero? minor_comparison = @minor <=> other.minor return minor_comparison unless minor_comparison.zero? @patch <=> other.patch end |
#hash ⇒ Integer
Generate hash value for this semantic version
187 188 189 |
# File 'lib/tty/link/semantic_version.rb', line 187 def hash [self.class, @major, @minor, @patch].hash end |
#inspect ⇒ String
Convert this semantic version to a string
199 200 201 |
# File 'lib/tty/link/semantic_version.rb', line 199 def inspect [@major, @minor, @patch].join(VERSION_SEPARATOR) end |