Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / lstrip.rb
1 #
2 #  lstrip.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:lstrip, :type => :rvalue, :doc => <<-EOS
7 Strips leading spaces to the left of a string.
8     EOS
9   ) do |arguments|
10
11     raise(Puppet::ParseError, "lstrip(): 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, 'lstrip(): Requires either array or string to work with')
17     end
18
19     if value.is_a?(Array)
20       # Numbers in Puppet are often string-encoded which is troublesome ...
21       result = value.collect { |i| i.is_a?(String) ? i.lstrip : i }
22     else
23       result = value.lstrip
24     end
25
26     return result
27   end
28 end
29
30 # vim: set ts=2 sw=2 et :