Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / bool2num.rb
1 #
2 # bool2num.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS
7     Converts a boolean to a number. Converts the values:
8       false, f, 0, n, and no to 0
9       true, t, 1, y, and yes to 1
10     Requires a single boolean or string as an input.
11     EOS
12   ) do |arguments|
13
14     raise(Puppet::ParseError, "bool2num(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
15
16     value = function_str2bool([arguments[0]])
17
18     # We have real boolean values as well ...
19     result = value ? 1 : 0
20
21     return result
22   end
23 end
24
25 # vim: set ts=2 sw=2 et :