4 module Puppet::Parser::Functions
5 newfunction(:num2bool, :type => :rvalue, :doc => <<-DOC
7 This function converts a number or a string representation of a number into a
10 > *Note:* that since Puppet 5.0.0 the same can be achieved with the Puppet Type System.
11 See the new() function in Puppet for the many available type conversions.
14 Boolean(0) # false for any zero or negative number
15 Boolean(1) # true for any positive number
19 raise(Puppet::ParseError, "num2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
24 when Numeric # rubocop:disable Lint/EmptyWhen : Required for the module to work
28 number = Float(number)
29 rescue ArgumentError => ex
30 raise(Puppet::ParseError, "num2bool(): '#{number}' does not look like a number: #{ex.message}")
35 rescue NoMethodError => ex
36 raise(Puppet::ParseError, "num2bool(): Unable to parse argument: #{ex.message}")
43 # Return true for any positive number and false otherwise
48 # vim: set ts=2 sw=2 et :