Class: VersionBoss::Gem::Version
- Inherits:
-
Object
- Object
- VersionBoss::Gem::Version
- Includes:
- Comparable
- Defined in:
- lib/version_boss/gem/version.rb
Overview
Parse and compare Ruby Gem version strings
This class will parse and validate a Ruby Gem version string
Two GemVersion objects can be compared using the spaceship operator (<=>) according to the rules of precedence defined in the Gem::Version class.
Direct Known Subclasses
Defined Under Namespace
Classes: PreReleaseIdentifier
Instance Attribute Summary collapse
-
#major ⇒ String
readonly
The major part of the version.
-
#minor ⇒ String
readonly
The minor part of the version.
-
#patch ⇒ String
readonly
The patch part of the version.
-
#pre_release ⇒ String
readonly
The pre_release part of the version.
-
#pre_release_identifiers ⇒ Array<String>
readonly
The pre_release identifiers of the version.
-
#version ⇒ String
readonly
The complete version string.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compare two GemVersion objects.
-
#==(other) ⇒ Boolean
Two versions are equal if their version strings are equal.
-
#initialize(version) ⇒ Version
constructor
Create a new GemVersion object.
-
#to_s ⇒ String
The string representation of a GemVersion is its version string.
-
#valid? ⇒ Boolean
Determine if the version string is a valid gem_version.
Constructor Details
#initialize(version) ⇒ Version
Create a new GemVersion object
66 67 68 69 70 71 |
# File 'lib/version_boss/gem/version.rb', line 66 def initialize(version) assert_version_must_be_a_string(version) @version = version parse assert_valid_version end |
Instance Attribute Details
#major ⇒ String (readonly)
The major part of the version
99 100 101 |
# File 'lib/version_boss/gem/version.rb', line 99 def major @major end |
#minor ⇒ String (readonly)
The minor part of the version
113 114 115 |
# File 'lib/version_boss/gem/version.rb', line 113 def minor @minor end |
#patch ⇒ String (readonly)
The patch part of the version
127 128 129 |
# File 'lib/version_boss/gem/version.rb', line 127 def patch @patch end |
#pre_release ⇒ String (readonly)
The pre_release part of the version
Will be an empty string if the version has no pre_release part.
147 148 149 |
# File 'lib/version_boss/gem/version.rb', line 147 def pre_release @pre_release end |
#pre_release_identifiers ⇒ Array<String> (readonly)
The pre_release identifiers of the version
165 166 167 |
# File 'lib/version_boss/gem/version.rb', line 165 def pre_release_identifiers @pre_release_identifiers end |
#version ⇒ String (readonly)
The complete version string
85 86 87 |
# File 'lib/version_boss/gem/version.rb', line 85 def version @version end |
Instance Method Details
#<=>(other) ⇒ Integer
Compare two GemVersion objects
See the Precedence Rules in the Semantic Versioning 2.0.0 Specification for more details.
203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/version_boss/gem/version.rb', line 203 def <=>(other) assert_other_is_a_gem_version(other) core_comparison = compare_core_parts(other) pre_release_comparison = compare_pre_release_part(other) return core_comparison unless core_comparison.zero? && !pre_release_comparison.zero? return 1 if pre_release.empty? return -1 if other.pre_release.empty? pre_release_comparison end |
#==(other) ⇒ Boolean
Two versions are equal if their version strings are equal
242 243 244 |
# File 'lib/version_boss/gem/version.rb', line 242 def ==(other) version == other.to_s end |
#to_s ⇒ String
The string representation of a GemVersion is its version string
253 254 255 |
# File 'lib/version_boss/gem/version.rb', line 253 def to_s version end |
#valid? ⇒ Boolean
Determine if the version string is a valid gem_version
Override this method in a subclass to provide extra or custom validation.
228 229 230 231 |
# File 'lib/version_boss/gem/version.rb', line 228 def valid? # If major is set, then so is everything else !major.nil? end |