Last change
on this file since 30903 was 30903, checked in by davidb, 7 years ago |
Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details
|
File size:
630 bytes
|
Line | |
---|
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
|
---|
Note:
See
TracBrowser
for help on using the repository browser.