Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / rstrip.rb
1 #
2 #  rstrip.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:rstrip, :type => :rvalue, :doc => <<-DOC
6     @summary
7       Strips leading spaces to the right of the string.
8
9     @return
10       the string with leading spaces removed
11
12     > *Note:* from Puppet 6.0.0, the compatible function with the same name in Puppet core
13     will be used instead of this function.
14     DOC
15              ) do |arguments|
16
17     raise(Puppet::ParseError, "rstrip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
18
19     value = arguments[0]
20
21     unless value.is_a?(Array) || value.is_a?(String)
22       raise(Puppet::ParseError, 'rstrip(): Requires either array or string to work with')
23     end
24
25     result = if value.is_a?(Array)
26                value.map { |i| i.is_a?(String) ? i.rstrip : i }
27              else
28                value.rstrip
29              end
30
31     return result
32   end
33 end
34
35 # vim: set ts=2 sw=2 et :