Puppet Function: bool2num

Defined in:
modules/stdlib/lib/puppet/parser/functions/bool2num.rb
Function type:
Ruby 3.x API

Overview

bool2num()Any

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.

Returns:

  • (Any)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'modules/stdlib/lib/puppet/parser/functions/bool2num.rb', line 5

newfunction(:bool2num, :type => :rvalue, :doc => <<-DOC
  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.
  DOC
           ) do |arguments|

  raise(Puppet::ParseError, "bool2num(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?

  value = function_str2bool([arguments[0]])

  # We have real boolean values as well ...
  result = value ? 1 : 0

  return result
end