module Puppet::Util::Package

Public Class Methods

versioncmp(version_a, version_b, ignore_trailing_zeroes = false) click to toggle source
   # File lib/puppet/util/package.rb
 3 def versioncmp(version_a, version_b, ignore_trailing_zeroes = false)
 4   vre = /[-.]|\d+|[^-.\d]+/
 5 
 6   if ignore_trailing_zeroes
 7     version_a = normalize(version_a)
 8     version_b = normalize(version_b)
 9   end
10 
11   ax = version_a.scan(vre)
12   bx = version_b.scan(vre)
13 
14   while (ax.length>0 && bx.length>0)
15     a = ax.shift
16     b = bx.shift
17 
18     next      if a == b
19     return -1 if a == '-'
20     return 1  if b == '-'
21     return -1 if a == '.'
22     return 1  if b == '.'
23     if a =~ /^\d+$/ && b =~ /^\d+$/
24       return a.to_s.upcase <=> b.to_s.upcase if a =~ /^0/ || b =~ /^0/
25       return a.to_i <=> b.to_i
26     end
27     return a.upcase <=> b.upcase
28   end
29   version_a <=> version_b
30 end

Private Class Methods

normalize(version) click to toggle source
   # File lib/puppet/util/package.rb
33 def self.normalize(version)
34   version = version.split('-')
35   version.first.sub!(/([\.0]+)$/, '')
36 
37   version.join('-')
38 end

Private Instance Methods

versioncmp(version_a, version_b, ignore_trailing_zeroes = false) click to toggle source
   # File lib/puppet/util/package.rb
 3 def versioncmp(version_a, version_b, ignore_trailing_zeroes = false)
 4   vre = /[-.]|\d+|[^-.\d]+/
 5 
 6   if ignore_trailing_zeroes
 7     version_a = normalize(version_a)
 8     version_b = normalize(version_b)
 9   end
10 
11   ax = version_a.scan(vre)
12   bx = version_b.scan(vre)
13 
14   while (ax.length>0 && bx.length>0)
15     a = ax.shift
16     b = bx.shift
17 
18     next      if a == b
19     return -1 if a == '-'
20     return 1  if b == '-'
21     return -1 if a == '.'
22     return 1  if b == '.'
23     if a =~ /^\d+$/ && b =~ /^\d+$/
24       return a.to_s.upcase <=> b.to_s.upcase if a =~ /^0/ || b =~ /^0/
25       return a.to_i <=> b.to_i
26     end
27     return a.upcase <=> b.upcase
28   end
29   version_a <=> version_b
30 end