Module: Pantheios::Util::VersionUtil
- Defined in:
- lib/pantheios/util/version_util.rb
Overview
version utilities
Class Method Summary collapse
-
.version_compare(lhs, rhs) ⇒ Object
Compares two version designators and returns a spaceship comparison result.
Class Method Details
.version_compare(lhs, rhs) ⇒ Object
Compares two version designators and returns a spaceship comparison result
Signature
- Parameters:
lhs[String, Array[Integer|String]] The left-hand comparandrhs[String, Array[Integer|String]] The right-hand comparand
- Returns:
- 0 if the two version designators represent exactly the same version
- <0 if the
lhsversion designator represents an earlier version than therhsversion designator -
0 if the
lhsversion designator represents a later version than therhsversion designator
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pantheios/util/version_util.rb', line 24 def self.version_compare lhs, rhs lhs = lhs.split('.') if String === lhs rhs = rhs.split('.') if String === rhs lhs = lhs.map { |n| n.to_i } rhs = rhs.map { |n| n.to_i } if lhs.size < rhs.size lhs += [ 0 ] * (rhs.size - lhs.size) else rhs += [ 0 ] * (lhs.size - rhs.size) end lhs <=> rhs end |