Class: SplitIoClient::Semver
- Inherits:
-
Object
- Object
- SplitIoClient::Semver
- Defined in:
- lib/splitclient-rb/engine/matchers/semver.rb
Constant Summary collapse
- METADATA_DELIMITER =
'+'
- PRE_RELEASE_DELIMITER =
'-'
- VALUE_DELIMITER =
'.'
Instance Attribute Summary collapse
-
#is_stable ⇒ Object
readonly
Returns the value of attribute is_stable.
-
#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.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.build(version, logger) ⇒ type
Class builder.
Instance Method Summary collapse
-
#compare(to_compare) ⇒ Object
Compare the current Semver object to a given Semver object, return: 0: if self == passed 1: if self > passed -1: if self < passed.
-
#initialize(version) ⇒ Semver
constructor
A new instance of Semver.
-
#remove_metadata_if_exists(old_version) ⇒ type
Check if there is any metadata characters in version.
Constructor Details
#initialize(version) ⇒ Semver
Returns a new instance of Semver.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/splitclient-rb/engine/matchers/semver.rb', line 11 def initialize(version) @major = 0 @minor = 0 @patch = 0 @pre_release = [] @is_stable = false @version = '' @metadata = '' parse(version) end |
Instance Attribute Details
#is_stable ⇒ Object (readonly)
Returns the value of attribute is_stable.
9 10 11 |
# File 'lib/splitclient-rb/engine/matchers/semver.rb', line 9 def is_stable @is_stable end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
9 10 11 |
# File 'lib/splitclient-rb/engine/matchers/semver.rb', line 9 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
9 10 11 |
# File 'lib/splitclient-rb/engine/matchers/semver.rb', line 9 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
9 10 11 |
# File 'lib/splitclient-rb/engine/matchers/semver.rb', line 9 def patch @patch end |
#pre_release ⇒ Object (readonly)
Returns the value of attribute pre_release.
9 10 11 |
# File 'lib/splitclient-rb/engine/matchers/semver.rb', line 9 def pre_release @pre_release end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/splitclient-rb/engine/matchers/semver.rb', line 9 def version @version end |
Class Method Details
.build(version, logger) ⇒ type
Class builder
28 29 30 31 32 33 34 35 36 |
# File 'lib/splitclient-rb/engine/matchers/semver.rb', line 28 def self.build(version, logger) new(version) rescue NoMethodError => e logger.error("Failed to parse Semver data, incorrect data type: #{e}") nil rescue StandardError => e logger.error("Failed to parse Semver data: #{e}") nil end |
Instance Method Details
#compare(to_compare) ⇒ Object
Compare the current Semver object to a given Semver object, return:
0: if self == passed
1: if self > passed
-1: if self < passed
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/splitclient-rb/engine/matchers/semver.rb', line 59 def compare(to_compare) return 0 if @version == to_compare.version # Compare major, minor, and patch versions numerically result = compare_attributes(to_compare) return result if result != 0 # Compare pre-release versions lexically compare_pre_release(to_compare) end |
#remove_metadata_if_exists(old_version) ⇒ type
Check if there is any metadata characters in version.
43 44 45 46 47 48 49 |
# File 'lib/splitclient-rb/engine/matchers/semver.rb', line 43 def (old_version) index = old_version.index(METADATA_DELIMITER) return old_version if index.nil? @metadata = old_version[index + 1, old_version.length] old_version[0, index] end |