5 module Puppet::Parser::Functions
6 newfunction(:any2bool, :type => :rvalue, :doc => <<-EOS
7 This converts 'anything' to a boolean. In practise it does the following:
9 * Strings such as Y,y,1,T,t,TRUE,yes,'true' will return true
10 * Strings such as 0,F,f,N,n,FALSE,no,'false' will return false
11 * Booleans will just return their original value
12 * Number (or a string representation of a number) > 0 will return true, otherwise false
13 * undef will return false
14 * Anything else will return true
18 raise(Puppet::ParseError, "any2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
20 # If argument is already Boolean, return it
21 if !!arguments[0] == arguments[0]
35 valid_float = !!Float(arg) rescue false
38 return function_num2bool( [ arguments[0] ] )
43 return function_num2bool( [ arguments[0] ] )
45 return function_str2bool( [ arguments[0] ] )
54 # vim: set ts=2 sw=2 et :