Class: AmplitudeExperiment::Evaluation::SemanticVersion
- Inherits:
-
Object
- Object
- AmplitudeExperiment::Evaluation::SemanticVersion
- Includes:
- Comparable
- Defined in:
- lib/experiment/evaluation/semantic_version.rb
Constant Summary collapse
- MAJOR_MINOR_REGEX =
'(\d+)\.(\d+)'- PATCH_REGEX =
'(\d+)'- PRERELEASE_REGEX =
'(-(([-\w]+\.?)*))?'- VERSION_PATTERN =
/^#{MAJOR_MINOR_REGEX}(\.#{PATCH_REGEX}#{PRERELEASE_REGEX})?$/.freeze
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.
-
#pre_release ⇒ Object
readonly
Returns the value of attribute pre_release.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(major, minor, patch, pre_release = nil) ⇒ SemanticVersion
constructor
A new instance of SemanticVersion.
Constructor Details
#initialize(major, minor, patch, pre_release = nil) ⇒ SemanticVersion
Returns a new instance of SemanticVersion.
15 16 17 18 19 20 |
# File 'lib/experiment/evaluation/semantic_version.rb', line 15 def initialize(major, minor, patch, pre_release = nil) @major = major @minor = minor @patch = patch @pre_release = pre_release end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
8 9 10 |
# File 'lib/experiment/evaluation/semantic_version.rb', line 8 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
8 9 10 |
# File 'lib/experiment/evaluation/semantic_version.rb', line 8 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
8 9 10 |
# File 'lib/experiment/evaluation/semantic_version.rb', line 8 def patch @patch end |
#pre_release ⇒ Object (readonly)
Returns the value of attribute pre_release.
8 9 10 |
# File 'lib/experiment/evaluation/semantic_version.rb', line 8 def pre_release @pre_release end |
Class Method Details
.parse(version) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/experiment/evaluation/semantic_version.rb', line 22 def self.parse(version) return nil if version.nil? match = VERSION_PATTERN.match(version) return nil unless match major = match[1].to_i minor = match[2].to_i patch = match[4]&.to_i || 0 pre_release = match[5] new(major, minor, patch, pre_release) end |
Instance Method Details
#<=>(other) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/experiment/evaluation/semantic_version.rb', line 36 def <=>(other) return nil unless other.is_a?(SemanticVersion) result = major <=> other.major return result unless result.zero? result = minor <=> other.minor return result unless result.zero? result = patch <=> other.patch return result unless result.zero? return 1 if !pre_release && other.pre_release return -1 if pre_release && !other.pre_release return 0 if !pre_release && !other.pre_release pre_release <=> other.pre_release end |