Class: Chef::VersionString
Overview
String-like object for version strings.
Instance Attribute Summary collapse
-
#parsed_version ⇒ Gem::Version
readonly
Parsed version object for the string.
Compat wrappers for String collapse
-
#*(other) ⇒ String
Compat wrapper for * to behave like a normal String.
-
#+(other) ⇒ String
Compat wrapper for + to behave like a normal String.
Comparison operators collapse
-
#!=(other) ⇒ Boolean
Compat wrapper for != based on <=>.
-
#<(other) ⇒ Boolean
Compat wrapper for < based on <=>.
-
#<=(other) ⇒ Boolean
Compat wrapper for <= based on <=>.
-
#<=>(other) ⇒ Integer
Compare a VersionString to an object.
-
#==(other) ⇒ Boolean
Compat wrapper for == based on <=>.
-
#>(other) ⇒ Boolean
Compat wrapper for > based on <=>.
-
#>=(other) ⇒ Boolean
Compat wrapper for >= based on <=>.
Matching operators collapse
-
#=~(other) ⇒ Boolean
Matching operator to support checking against a requirement string.
Instance Method Summary collapse
-
#initialize(val) ⇒ VersionString
constructor
Create a new VersionString from an input String.
Methods inherited from String
Methods included from Mixin::WideString
#utf8_to_wide, #wide_to_utf8, #wstring
Methods included from Shell::Extensions::String
Constructor Details
#initialize(val) ⇒ VersionString
Create a new VersionString from an input String.
29 30 31 32 |
# File 'lib/chef/version_string.rb', line 29 def initialize(val) super @parsed_version = ::Gem::Version.create(self) end |
Instance Attribute Details
#parsed_version ⇒ Gem::Version (readonly)
Parsed version object for the string.
24 25 26 |
# File 'lib/chef/version_string.rb', line 24 def parsed_version @parsed_version end |
Instance Method Details
#!=(other) ⇒ Boolean
Compat wrapper for != based on <=>.
87 88 89 |
# File 'lib/chef/version_string.rb', line 87 def !=(other) (self <=> other) != 0 end |
#*(other) ⇒ String
Compat wrapper for * to behave like a normal String.
48 49 50 |
# File 'lib/chef/version_string.rb', line 48 def *(other) to_s * other end |
#+(other) ⇒ String
Compat wrapper for + to behave like a normal String.
40 41 42 |
# File 'lib/chef/version_string.rb', line 40 def +(other) to_s + other end |
#<(other) ⇒ Boolean
Compat wrapper for < based on <=>.
95 96 97 |
# File 'lib/chef/version_string.rb', line 95 def <(other) (self <=> other) < 0 end |
#<=(other) ⇒ Boolean
Compat wrapper for <= based on <=>.
103 104 105 |
# File 'lib/chef/version_string.rb', line 103 def <=(other) (self <=> other) < 1 end |
#<=>(other) ⇒ Integer
Compare a VersionString to an object. If compared to another VersionString then sort like ‘Gem::Version`, otherwise try to treat the other object as a version but fall back to normal string comparison.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/chef/version_string.rb', line 60 def <=>(other) other_ver = case other when VersionString other.parsed_version else begin Gem::Version.create(other.to_s) rescue ArgumentError # Comparing to a string that isn't a version. return super end end parsed_version <=> other_ver end |
#==(other) ⇒ Boolean
Compat wrapper for == based on <=>.
79 80 81 |
# File 'lib/chef/version_string.rb', line 79 def ==(other) (self <=> other) == 0 end |
#=~(other) ⇒ Boolean
Matching operator to support checking against a requirement string.
133 134 135 136 137 138 139 140 |
# File 'lib/chef/version_string.rb', line 133 def =~(other) case other when Regexp super else Gem::Requirement.create(other) =~ parsed_version end end |
#>(other) ⇒ Boolean
Compat wrapper for > based on <=>.
111 112 113 |
# File 'lib/chef/version_string.rb', line 111 def >(other) (self <=> other) > 0 end |
#>=(other) ⇒ Boolean
Compat wrapper for >= based on <=>.
119 120 121 |
# File 'lib/chef/version_string.rb', line 119 def >=(other) (self <=> other) > -1 end |