4 module Puppet::Parser::Functions
5 newfunction(:bool2num, :type => :rvalue, :doc => <<-DOC
7 Converts a boolean to a number.
11 false, f, 0, n, and no to 0
12 true, t, 1, y, and yes to 1
14 Requires a single boolean or string as an input.
17 since Puppet 5.0.0 it is possible to create new data types for almost any
18 datatype using the type system and the built-in
19 [`Numeric.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-numeric),
20 [`Integer.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-integer), and
21 [`Float.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-float)
22 function are used to convert to numeric values.
24 notice(Integer(false)) # Notices 0
25 notice(Float(true)) # Notices 1.0
28 @return [Integer] The converted value as a number
32 raise(Puppet::ParseError, "bool2num(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
34 value = function_str2bool([arguments[0]])
36 # We have real boolean values as well ...
37 result = value ? 1 : 0
43 # vim: set ts=2 sw=2 et :