Module: VirtualBox::AbstractModel::VersionMatcher

Included in:
Attributable, Relatable
Defined in:
lib/virtualbox/abstract_model/version_matcher.rb

Instance Method Summary collapse

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)
    message = "Required version: #{req}; Current: #{cur}"
    raise Exceptions::UnsupportedVersionException.new(message)
  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.

Parameters:

  • version (String)

Returns:

  • (Array)


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.

Returns:

  • (Boolean)


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