2011-04-29 18:27:50 +02:00
|
|
|
#
|
|
|
|
# capitalize.rb
|
|
|
|
#
|
|
|
|
|
|
|
|
module Puppet::Parser::Functions
|
|
|
|
newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS
|
2011-07-29 20:22:30 +02:00
|
|
|
Capitalizes the first letter of a string or array of strings.
|
|
|
|
Requires either a single string or an array as an input.
|
2011-04-29 18:27:50 +02:00
|
|
|
EOS
|
|
|
|
) do |arguments|
|
|
|
|
|
|
|
|
raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " +
|
|
|
|
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
|
|
|
|
|
|
value = arguments[0]
|
|
|
|
|
2014-04-22 09:36:28 +02:00
|
|
|
unless value.is_a?(Array) || value.is_a?(String)
|
2011-04-30 00:18:58 +02:00
|
|
|
raise(Puppet::ParseError, 'capitalize(): Requires either ' +
|
2011-04-29 18:27:50 +02:00
|
|
|
'array or string to work with')
|
|
|
|
end
|
|
|
|
|
|
|
|
if value.is_a?(Array)
|
2011-04-30 03:54:47 +02:00
|
|
|
# Numbers in Puppet are often string-encoded which is troublesome ...
|
2011-04-29 18:27:50 +02:00
|
|
|
result = value.collect { |i| i.is_a?(String) ? i.capitalize : i }
|
|
|
|
else
|
|
|
|
result = value.capitalize
|
|
|
|
end
|
|
|
|
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 et :
|