Class: VersionCompare

Inherits:
Object
  • Object
show all
Defined in:
lib/common/version_compare.rb

Class Method Summary collapse

Class Method Details

.lesser_or_equal?(version1, version2) ⇒ Boolean

Compares two version strings. Returns true if version1 <= version2 and false otherwise

Parameters:

  • version1 (String)
  • version2 (String)

Returns:

  • (Boolean)

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/common/version_compare.rb', line 12

def self.lesser_or_equal?(version1, version2)
  # Prepend a '0' if the version starts with a '.'
  version1 = "0#{version1}" if version1 && version1[0,1] == '.'
  version2 = "0#{version2}" if version2 && version2[0,1] == '.'

  return true if (version1 == version2)
  # Both versions must be set
  return false unless (version1 and version2)
  return false if (version1.empty? or version2.empty?)
  begin
    return true if (Gem::Version.new(version1) < Gem::Version.new(version2))
  rescue ArgumentError => e
    # Example: ArgumentError: Malformed version number string a
    return false if e.message =~ /Malformed version number string/
    raise
  end
  return false
end