]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/strip.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / strip.rb
1 #
2 #  strip.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:strip, :type => :rvalue, :doc => <<-EOS
7 This function removes leading and trailing whitespace from a string or from
8 every string inside an array.
9
10 *Examples:*
11
12     strip("    aaa   ")
13
14 Would result in: "aaa"
15     EOS
16   ) do |arguments|
17
18     raise(Puppet::ParseError, "strip(): Wrong number of arguments " +
19       "given (#{arguments.size} for 1)") if arguments.size < 1
20
21     value = arguments[0]
22
23     unless value.is_a?(Array) || value.is_a?(String)
24       raise(Puppet::ParseError, 'strip(): Requires either ' +
25         'array or string to work with')
26     end
27
28     if value.is_a?(Array)
29       result = value.collect { |i| i.is_a?(String) ? i.strip : i }
30     else
31       result = value.strip
32     end
33
34     return result
35   end
36 end
37
38 # vim: set ts=2 sw=2 et :