]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/is_float.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / is_float.rb
1 #
2 # is_float.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:is_float, :type => :rvalue, :doc => <<-EOS
7 Returns true if the variable passed to this function is a float.
8     EOS
9   ) do |arguments|
10
11     if (arguments.size != 1) then
12       raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+
13         "given #{arguments.size} for 1")
14     end
15
16     value = arguments[0]
17
18     # Only allow Numeric or String types
19     return false unless value.is_a?(Numeric) or value.is_a?(String)
20
21     if value != value.to_f.to_s and !value.is_a? Float then
22       return false
23     else
24       return true
25     end
26
27   end
28 end
29
30 # vim: set ts=2 sw=2 et :