5 module Puppet::Parser::Functions
6 newfunction(:abs, :type => :rvalue, :doc => <<-EOS
7 Returns the absolute value of a number, for example -34.56 becomes
8 34.56. Takes a single integer and float value as an argument.
12 raise(Puppet::ParseError, "abs(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
16 # Numbers in Puppet are often string-encoded which is troublesome ...
17 if value.is_a?(String)
18 if value.match(/^-?(?:\d+)(?:\.\d+){1}$/)
20 elsif value.match(/^-?\d+$/)
23 raise(Puppet::ParseError, 'abs(): Requires float or integer to work with')
27 # We have numeric value to handle ...
34 # vim: set ts=2 sw=2 et :