source: other-projects/hathitrust/vagrant-solr-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/max.rb@ 30960

Last change on this file since 30960 was 30960, checked in by davidb, 7 years ago

Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster

File size: 630 bytes
Line 
1module 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
21end
Note: See TracBrowser for help on using the repository browser.