99874e4683e22c400ec0b245b5413ed4fe5c7c66
[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     Strips leading spaces to the left of a string.
7
8     Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
9     will be used instead of this function.
10     DOC
11              ) do |arguments|
12
13     raise(Puppet::ParseError, "lstrip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
14
15     value = arguments[0]
16
17     unless value.is_a?(Array) || value.is_a?(String)
18       raise(Puppet::ParseError, 'lstrip(): Requires either array or string to work with')
19     end
20
21     result = if value.is_a?(Array)
22                # Numbers in Puppet are often string-encoded which is troublesome ...
23                value.map { |i| i.is_a?(String) ? i.lstrip : i }
24              else
25                value.lstrip
26              end
27
28     return result
29   end
30 end
31
32 # vim: set ts=2 sw=2 et :