Module: VirtualBox::AbstractModel::VersionMatcher
- Included in:
- Attributable, Relatable
- Defined in:
- lib/virtualbox/abstract_model/version_matcher.rb
Instance Method Summary collapse
-
#assert_version_match(req, cur) ⇒ Object
Asserts that two versions match.
-
#split_version(version) ⇒ Array
Splits a version string into a two-item array with the parts of the version, respectively.
-
#version_match?(requirement, current) ⇒ Boolean
Checks if a given version requirement matches the current version.
Instance Method Details
#assert_version_match(req, cur) ⇒ Object
Asserts that two versions match. Otherwise raises an exception.
6 7 8 9 10 11 |
# File 'lib/virtualbox/abstract_model/version_matcher.rb', line 6 def assert_version_match(req, cur) if !version_match?(req, cur) = "Required version: #{req}; Current: #{cur}" raise Exceptions::UnsupportedVersionException.new() end end |
#split_version(version) ⇒ Array
Splits a version string into a two-item array with the parts of the version, respectively. If the version has more than two parts, the rest are ignored.
27 28 29 30 31 |
# File 'lib/virtualbox/abstract_model/version_matcher.rb', line 27 def split_version(version) version.split(/\./)[0,2] rescue Exception [] end |
#version_match?(requirement, current) ⇒ Boolean
Checks if a given version requirement matches the current version.
17 18 19 |
# File 'lib/virtualbox/abstract_model/version_matcher.rb', line 17 def version_match?(requirement, current) split_version(requirement) == split_version(current) end |