4 module Puppet::Parser::Functions
5 newfunction(:num2bool, :type => :rvalue, :doc => <<-DOC
6 This function converts a number or a string representation of a number into a
7 true boolean. Zero or anything non-numeric becomes false. Numbers higher then 0
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.
18 raise(Puppet::ParseError, "num2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
23 when Numeric # rubocop:disable Lint/EmptyWhen : Required for the module to work
27 number = Float(number)
28 rescue ArgumentError => ex
29 raise(Puppet::ParseError, "num2bool(): '#{number}' does not look like a number: #{ex.message}")
34 rescue NoMethodError => ex
35 raise(Puppet::ParseError, "num2bool(): Unable to parse argument: #{ex.message}")
42 # Return true for any positive number and false otherwise
47 # vim: set ts=2 sw=2 et :