Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / min.rb
1 #
2 # min.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:min, :type => :rvalue, :doc => <<-DOC
6     @summary
7       **Deprecated:** Returns the lowest value of all arguments.
8
9     Requires at least one argument.
10
11     @return
12       The lowest value among the given arguments
13
14     > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a
15     built-in [`min`](https://puppet.com/docs/puppet/latest/function.html#min) function.
16     DOC
17              ) do |args|
18
19     raise(Puppet::ParseError, 'min(): Wrong number of arguments need at least one') if args.empty?
20
21     # Sometimes we get numbers as numerics and sometimes as strings.
22     # We try to compare them as numbers when possible
23     return args.min do |a, b|
24       if a.to_s =~ %r{\A^-?\d+(.\d+)?\z} && b.to_s =~ %r{\A-?\d+(.\d+)?\z}
25         a.to_f <=> b.to_f
26       else
27         a.to_s <=> b.to_s
28       end
29     end
30   end
31 end