Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / capitalize.rb
1 #
2 #  capitalize.rb
3 #  Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085.
4 #
5 module Puppet::Parser::Functions
6   newfunction(:capitalize, :type => :rvalue, :doc => <<-DOC
7     Capitalizes the first letter of a string or array of strings.
8     Requires either a single string or an array as an input.
9
10     Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
11     will be used instead of this function.
12     DOC
13              ) do |arguments|
14
15     raise(Puppet::ParseError, "capitalize(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
16
17     value = arguments[0]
18
19     unless value.is_a?(Array) || value.is_a?(String)
20       raise(Puppet::ParseError, 'capitalize(): Requires either array or string to work with')
21     end
22
23     result = if value.is_a?(Array)
24                # Numbers in Puppet are often string-encoded which is troublesome ...
25                value.map { |i| i.is_a?(String) ? i.capitalize : i }
26              else
27                value.capitalize
28              end
29
30     return result
31   end
32 end