Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / rstrip.rb
1 #
2 #  rstrip.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS
7 Strips leading spaces to the right of the string.
8     EOS
9   ) do |arguments|
10
11     raise(Puppet::ParseError, "rstrip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
12
13     value = arguments[0]
14
15     unless value.is_a?(Array) || value.is_a?(String)
16       raise(Puppet::ParseError, 'rstrip(): Requires either array or string to work with')
17     end
18
19     if value.is_a?(Array)
20       result = value.collect { |i| i.is_a?(String) ? i.rstrip : i }
21     else
22       result = value.rstrip
23     end
24
25     return result
26   end
27 end
28
29 # vim: set ts=2 sw=2 et :