Update stdlib
[mirror/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     function_deprecation([:is_float, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Float. There is further documentation for validate_legacy function in the README.'])
12
13     if (arguments.size != 1) then
14       raise(Puppet::ParseError, "is_float(): Wrong number of arguments given #{arguments.size} for 1")
15     end
16
17     value = arguments[0]
18
19     # Only allow Numeric or String types
20     return false unless value.is_a?(Numeric) or value.is_a?(String)
21
22     if value != value.to_f.to_s and !value.is_a? Float then
23       return false
24     else
25       return true
26     end
27
28   end
29 end
30
31 # vim: set ts=2 sw=2 et :