Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / strip.rb
1 #
2 #  strip.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:strip, :type => :rvalue, :doc => <<-DOC
6     This function removes leading and trailing whitespace from a string or from
7     every string inside an array.
8
9     *Examples:*
10
11         strip("    aaa   ")
12
13     Would result in: "aaa"
14
15     Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
16     will be used instead of this function.
17     DOC
18              ) do |arguments|
19
20     raise(Puppet::ParseError, "strip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
21
22     value = arguments[0]
23
24     unless value.is_a?(Array) || value.is_a?(String)
25       raise(Puppet::ParseError, 'strip(): Requires either array or string to work with')
26     end
27
28     result = if value.is_a?(Array)
29                value.map { |i| i.is_a?(String) ? i.strip : i }
30              else
31                value.strip
32              end
33
34     return result
35   end
36 end
37
38 # vim: set ts=2 sw=2 et :