Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / max.rb
1 #
2 # max.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:max, :type => :rvalue, :doc => <<-DOC
6     Returns the highest value of all arguments.
7     Requires at least one argument.
8
9     Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
10     will be used instead of this function.
11     DOC
12              ) do |args|
13
14     raise(Puppet::ParseError, 'max(): Wrong number of arguments need at least one') if args.empty?
15
16     # Sometimes we get numbers as numerics and sometimes as strings.
17     # We try to compare them as numbers when possible
18     return args.max do |a, b|
19       if a.to_s =~ %r{\A-?\d+(.\d+)?\z} && b.to_s =~ %r{\A-?\d+(.\d+)?\z}
20         a.to_f <=> b.to_f
21       else
22         a.to_s <=> b.to_s
23       end
24     end
25   end
26 end