Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / lstrip.rb
1 #
2 #  lstrip.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:lstrip, :type => :rvalue, :doc => <<-DOC
6     @summary
7       **Deprecated:** Strips leading spaces to the left of a string.
8
9     @return [String]
10       The stripped string
11
12     > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a
13     built-in [`max`](https://puppet.com/docs/puppet/latest/function.html#max) function.
14     DOC
15              ) do |arguments|
16
17     raise(Puppet::ParseError, "lstrip(): 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, 'lstrip(): Requires either array or string to work with')
23     end
24
25     result = if value.is_a?(Array)
26                # Numbers in Puppet are often string-encoded which is troublesome ...
27                value.map { |i| i.is_a?(String) ? i.lstrip : i }
28              else
29                value.lstrip
30              end
31
32     return result
33   end
34 end
35
36 # vim: set ts=2 sw=2 et :