#
module Puppet::Parser::Functions
newfunction(:clamp, :type => :rvalue, :arity => -2, :doc => <<-DOC
- Clamps value to a range.
+ @summary
+ Keeps value within the range [Min, X, Max] by sort based on integer value
+ (parameter order doesn't matter).
- Note: From Puppet 6.0.0 this can be done with only core Puppet like this:
- [$minval, $maxval, $value_to_clamp].sort[1]
+ Strings are converted and compared numerically. Arrays of values are flattened
+ into a list for further handling.
+
+ @example Example usage
+
+ clamp('24', [575, 187])` returns 187.
+ clamp(16, 88, 661)` returns 88.
+ clamp([4, 3, '99'])` returns 4.
+
+ > *Note:*
+ From Puppet 6.0.0 this can be done with only core Puppet like this:
+ `[$minval, $maxval, $value_to_clamp].sort[1]`
+
+ @return [Array[Integer]] The sorted Array
DOC
) do |args|