5 module Puppet::Parser::Functions
6 newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS
7 This converts a string to a boolean. This attempt to convert strings that
8 contain things like: y, 1, t, true to 'true' and strings that contain things
9 like: 0, f, n, false, no to 'false'.
13 raise(Puppet::ParseError, "str2bool(): Wrong number of arguments " +
14 "given (#{arguments.size} for 1)") if arguments.size < 1
18 unless string.is_a?(String)
19 raise(Puppet::ParseError, 'str2bool(): Requires either ' +
20 'string to work with')
23 # We consider all the yes, no, y, n and so on too ...
26 # This is how undef looks like in Puppet ...
27 # We yield false in this case.
29 when /^$/, '' then false # Empty string will be false ...
30 when /^(1|t|y|true|yes)$/ then true
31 when /^(0|f|n|false|no)$/ then false
32 when /^(undef|undefined)$/ then false # This is not likely to happen ...
34 raise(Puppet::ParseError, 'str2bool(): Unknown type of boolean given')
41 # vim: set ts=2 sw=2 et :