Mercurial > repos > other > Puppet
comparison modules/stdlib/lib/puppet/parser/functions/min.rb @ 272:c42fb28cff86
Update to a newer Python module
This also pulls in an EPEL module (which we don't use) and a newer
stdlib version.
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 03 Jan 2020 19:56:04 +0000 |
parents | 956e484adc12 |
children | d9352a684e62 |
comparison
equal
deleted
inserted
replaced
271:c62728474654 | 272:c42fb28cff86 |
---|---|
1 # | |
2 # min.rb | |
3 # | |
1 module Puppet::Parser::Functions | 4 module Puppet::Parser::Functions |
2 newfunction(:min, :type => :rvalue, :doc => <<-EOS | 5 newfunction(:min, :type => :rvalue, :doc => <<-DOC |
3 Returns the lowest value of all arguments. | 6 Returns the lowest value of all arguments. |
4 Requires at least one argument. | 7 Requires at least one argument. |
5 EOS | 8 DOC |
6 ) do |args| | 9 ) do |args| |
7 | 10 |
8 raise(Puppet::ParseError, "min(): Wrong number of arguments " + | 11 raise(Puppet::ParseError, 'min(): Wrong number of arguments need at least one') if args.empty? |
9 "need at least one") if args.size == 0 | |
10 | 12 |
11 # Sometimes we get numbers as numerics and sometimes as strings. | 13 # Sometimes we get numbers as numerics and sometimes as strings. |
12 # We try to compare them as numbers when possible | 14 # We try to compare them as numbers when possible |
13 return args.min do |a,b| | 15 return args.min do |a, b| |
14 if a.to_s =~ /\A^-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then | 16 if a.to_s =~ %r{\A^-?\d+(.\d+)?\z} && b.to_s =~ %r{\A-?\d+(.\d+)?\z} |
15 a.to_f <=> b.to_f | 17 a.to_f <=> b.to_f |
16 else | 18 else |
17 a.to_s <=> b.to_s | 19 a.to_s <=> b.to_s |
18 end | 20 end |
19 end | 21 end |