summaryrefslogtreecommitdiff
path: root/lib/puppet
diff options
context:
space:
mode:
authorSteve Huff <shuff@vecna.org>2013-04-01 11:44:09 -0400
committerSteve Huff <shuff@vecna.org>2013-04-01 11:44:09 -0400
commitc372f177708df4c844337e9901646b7b84b86cd8 (patch)
treea946ee1edb5862430106b35150d82aef3a61d8fe /lib/puppet
parent8d217f0012fef332642faf485ad187773a95bcc1 (diff)
Cleanup per adrianthebo suggestions
* use Float() to process string arguments * get rid of doubly nested arrays * removing needless ternary operator * improving error message handling
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/parser/functions/num2bool.rb22
1 files changed, 9 insertions, 13 deletions
diff --git a/lib/puppet/parser/functions/num2bool.rb b/lib/puppet/parser/functions/num2bool.rb
index cf98f80..af0e6ed 100644
--- a/lib/puppet/parser/functions/num2bool.rb
+++ b/lib/puppet/parser/functions/num2bool.rb
@@ -19,28 +19,24 @@ become true.
when Numeric
# Yay, it's a number
when String
- # Deal with strings later
+ begin
+ number = Float(number)
+ rescue ArgumentError => ex
+ raise(Puppet::ParseError, "num2bool(): '#{number}' does not look like a number: #{ex.message}")
+ end
else
begin
number = number.to_s
- rescue NoMethodError
- raise(Puppet::ParseError, 'num2bool(): Unable to parse argument: ' + $!)
- end
- end
-
- case number
- when String
- # Only accept strings that look somewhat like numbers
- unless number =~ /^-?\d+/
- raise(Puppet::ParseError, "num2bool(): '#{number}' does not look like a number")
+ rescue NoMethodError => ex
+ raise(Puppet::ParseError, "num2bool(): Unable to parse argument: #{ex.message}")
end
end
- # Truncate floats
+ # Truncate Floats
number = number.to_i
# Return true for any positive number and false otherwise
- return number > 0 ? true : false
+ return number > 0
end
end