Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / floor.rb
1 module Puppet::Parser::Functions
2   newfunction(:floor, :type => :rvalue, :doc => <<-EOS
3     Returns the largest integer less or equal to the argument.
4     Takes a single numeric value as an argument.
5     EOS
6   ) do |arguments|
7
8     raise(Puppet::ParseError, "floor(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
9
10     begin
11       arg = Float(arguments[0])
12     rescue TypeError, ArgumentError => e
13       raise(Puppet::ParseError, "floor(): Wrong argument type given (#{arguments[0]} for Numeric)")
14     end
15
16     raise(Puppet::ParseError, "floor(): Wrong argument type given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
17
18     arg.floor
19   end
20 end
21
22 # vim: set ts=2 sw=2 et :