summaryrefslogtreecommitdiff
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorKristof Willaert <kristof.willaert@gmail.com>2013-03-19 10:00:57 +0100
committerKristof Willaert <kristof.willaert@gmail.com>2013-03-19 10:00:57 +0100
commit05273419e1c8b34115ede15b1d8a8739f6a0db00 (patch)
treea2177d46f853cd219507d9a0c4d1e339d50fae45 /lib/puppet/parser
parentfc2352f346b7b7acfc1a51afe4d17310cdcc4213 (diff)
Add floor function implementation and unit tests
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/functions/floor.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/floor.rb b/lib/puppet/parser/functions/floor.rb
new file mode 100644
index 0000000..a401923
--- /dev/null
+++ b/lib/puppet/parser/functions/floor.rb
@@ -0,0 +1,20 @@
+module Puppet::Parser::Functions
+ newfunction(:floor, :type => :rvalue, :doc => <<-EOS
+ Returns the largest integer less or equal to the argument.
+ Takes a single numeric value as an argument.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "floor(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+
+ arg = arguments[0]
+
+ raise(Puppet::ParseError, "floor(): Wrong argument type " +
+ "given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
+
+ arg.floor
+ end
+end
+
+# vim: set ts=2 sw=2 et :