Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / bool2num.rb
1 #
2 # bool2num.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:bool2num, :type => :rvalue, :doc => <<-DOC
6     Converts a boolean to a number. Converts the values:
7       false, f, 0, n, and no to 0
8       true, t, 1, y, and yes to 1
9     Requires a single boolean or string as an input.
10
11     Note that since Puppet 5.0.0 it is possible to create new data types for almost any
12     datatype using the type system and the built-in
13     [`Numeric.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-numeric),
14     [`Integer.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-integer), and
15     [`Float.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-float)
16     function are used to convert to numeric values.
17
18         notice(Integer(false)) # Notices 0
19         notice(Float(true))    # Notices 1.0
20     DOC
21              ) do |arguments|
22
23     raise(Puppet::ParseError, "bool2num(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
24
25     value = function_str2bool([arguments[0]])
26
27     # We have real boolean values as well ...
28     result = value ? 1 : 0
29
30     return result
31   end
32 end
33
34 # vim: set ts=2 sw=2 et :