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.
5 module Puppet::Parser::Functions
6 newfunction(:capitalize, :type => :rvalue, :doc => <<-DOC
8 **Deprecated** Capitalizes the first letter of a string or array of strings.
10 Requires either a single string or an array as an input.
13 **Deprecated** from Puppet 6.0.0, yhis function has been replaced with a
14 built-in [`capitalize`](https://puppet.com/docs/puppet/latest/function.html#capitalize)
17 @return [String] The converted String, if it was a String that was given
18 @return [Array[String]] The converted Array, if it was a Array that was given
22 raise(Puppet::ParseError, "capitalize(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
26 unless value.is_a?(Array) || value.is_a?(String)
27 raise(Puppet::ParseError, 'capitalize(): Requires either array or string to work with')
30 result = if value.is_a?(Array)
31 # Numbers in Puppet are often string-encoded which is troublesome ...
32 value.map { |i| i.is_a?(String) ? i.capitalize : i }