4 module Puppet::Parser::Functions
5 newfunction(:chomp, :type => :rvalue, :doc => <<-DOC
6 Removes the record separator from the end of a string or an array of
7 strings, for example `hello\n` becomes `hello`.
8 Requires a single string or array as an input.
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.
15 raise(Puppet::ParseError, "chomp(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
19 unless value.is_a?(Array) || value.is_a?(String)
20 raise(Puppet::ParseError, 'chomp(): Requires either array or string to work with')
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.chomp : i }
34 # vim: set ts=2 sw=2 et :