2011-04-25 04:19:10 +02:00
|
|
|
#
|
|
|
|
# bool2num.rb
|
|
|
|
#
|
|
|
|
|
|
|
|
module Puppet::Parser::Functions
|
2011-04-29 21:10:53 +02:00
|
|
|
newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS
|
2011-07-29 20:22:30 +02:00
|
|
|
Converts a boolean to a number. Converts the values:
|
|
|
|
false, f, 0, n, and no to 0
|
|
|
|
true, t, 1, y, and yes to 1
|
|
|
|
Requires a single boolean or string as an input.
|
2011-04-25 04:19:10 +02:00
|
|
|
EOS
|
|
|
|
) do |arguments|
|
|
|
|
|
2011-04-29 21:10:53 +02:00
|
|
|
raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " +
|
2011-04-25 04:19:10 +02:00
|
|
|
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
|
|
|
2014-05-23 08:44:50 +02:00
|
|
|
value = function_str2bool([arguments[0]])
|
2011-04-25 04:19:10 +02:00
|
|
|
|
2011-04-30 03:57:48 +02:00
|
|
|
# We have real boolean values as well ...
|
|
|
|
result = value ? 1 : 0
|
|
|
|
|
2011-04-25 04:19:10 +02:00
|
|
|
return result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 et :
|