Class List Method List File List

# Class: VersionCompare

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

## Class Method Summary (collapse)

- + (Boolean) is_newer_or_same?(version1, version2)

  Compares two version strings.

## Class Method Details

### + (`Boolean`) is_newer_or_same?(version1, version2)

Compares two version strings. Returns true if version1 is equal to version2 or when version1 is older than version2

Parameters:

- version1 (`String`)
- version2 (`String`)

Returns:

- (`Boolean`)

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

    def self.is_newer_or_same?(version1, version2)
       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