module SyncWrap::VersionSupport
A Support module for parsing and comparing version strings.
Protected Instance Methods
version_gte?( v1, v2 )
click to toggle source
Return true if v1 and v2 are not nil, (auto converted) array positions are type compatible and compare as v1 >= v2.
# File lib/syncwrap/version_support.rb, line 45 def version_gte?( v1, v2 ) v1 = version_string_to_a( v1 ) v2 = version_string_to_a( v2 ) c = v1 && v2 && ( v1 <=> v2 ) #-> nil for String/Integer mix c && c >= 0 end
version_lt?( v1, v2 )
click to toggle source
Return true if v1 and v2 are not nil, (auto converted) array positions are type compatible and compare v1 < v2.
# File lib/syncwrap/version_support.rb, line 54 def version_lt?( v1, v2 ) v1 = version_string_to_a( v1 ) v2 = version_string_to_a( v2 ) c = v1 && v2 && ( v1 <=> v2 ) #-> nil for String/Integer mix c && c < 0 end
version_string_to_a( v )
click to toggle source
Convert version decimal String to Array of Integer or String values. The characters '.' and '-' are treated as delimiters. Any remaining non-digit in a segment results in a String being returned for that segment. Return v if not a String (incl nil).
# File lib/syncwrap/version_support.rb, line 29 def version_string_to_a( v ) if v.is_a?( String ) v.split(/[.\-]/).map do |p| if p =~ /^\d+$/ p.to_i else p end end else v end end