]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/max.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / max.rb
1 module Puppet::Parser::Functions
2   newfunction(:max, :type => :rvalue, :doc => <<-EOS
3     Returns the highest value of all arguments.
4     Requires at least one argument.
5     EOS
6   ) do |args|
7
8     raise(Puppet::ParseError, "max(): Wrong number of arguments " +
9           "need at least one") if args.size == 0
10
11     # Sometimes we get numbers as numerics and sometimes as strings.
12     # We try to compare them as numbers when possible
13     return args.max do |a,b|
14       if a.to_s =~ /\A-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then
15         a.to_f <=> b.to_f
16       else
17         a.to_s <=> b.to_s
18       end
19     end
20   end
21 end