Last change
on this file since 30960 was 30960, checked in by davidb, 8 years ago |
Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster
|
File size:
630 bytes
|
Line | |
---|
1 | module Puppet::Parser::Functions
|
---|
2 | newfunction(:min, :type => :rvalue, :doc => <<-EOS
|
---|
3 | Returns the lowest value of all arguments.
|
---|
4 | Requires at least one argument.
|
---|
5 | EOS
|
---|
6 | ) do |args|
|
---|
7 |
|
---|
8 | raise(Puppet::ParseError, "min(): 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.min 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.