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