summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-29 23:16:26 +0100
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-29 23:16:26 +0100
commit6d9e5efe380437420a53762e21d73dc1c8262f64 (patch)
treef77e18c70b87212c630a47051d69f8bd14b34c1b
parentf4f47f6d5f38e9d72fd0fc4701e8cb2b78fc238e (diff)
downloadpuppet-stdlib-6d9e5efe380437420a53762e21d73dc1c8262f64.tar.gz
puppet-stdlib-6d9e5efe380437420a53762e21d73dc1c8262f64.tar.bz2
Minor changes.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r--bool2num.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/bool2num.rb b/bool2num.rb
index 9de7f50..65c8295 100644
--- a/bool2num.rb
+++ b/bool2num.rb
@@ -13,23 +13,24 @@ module Puppet::Parser::Functions
value = arguments[0]
klass = value.class
- if not [FalseClass, String, TrueClass].include?(klass)
- raise(Puppet::ParseError, 'bool2num(): Requires either an ' +
+ # We can have either true or false, or string which resembles boolean ...
+ unless [FalseClass, TrueClass, String].include?(klass)
+ raise(Puppet::ParseError, 'bool2num(): Requires either ' +
'boolean or string to work with')
end
if value.is_a?(String)
+ # We consider all the yes, no, y, n and so on too ...
result = case value
#
# This is how undef looks like in Puppet ...
# We yield 0 (or false if you wish) in this case.
#
- when /^$/, '' then 0
- when /^(1|t|y|true|yes)$/ then 1
- when /^(0|f|n|false|no)$/ then 0
- # This is not likely to happen ...
- when /^(undef|undefined)$/ then 0
+ when /^$/, '' then 0 # Empty string will be false ...
+ when /^(1|t|y|true|yes)$/ then 1
+ when /^(0|f|n|false|no)$/ then 0
+ when /^(undef|undefined)$/ then 0 # This is not likely to happen ...
else
raise(Puppet::ParseError, 'bool2num(): Unknown type of boolean given')
end