<commit_before>#
#  camelcase.rb
#  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.
#
module Puppet::Parser::Functions
  newfunction(:camelcase, :type => :rvalue, :doc => <<-DOC
    Converts the case of a string or all strings in an array to camel case.
  DOC
             ) do |arguments|

    raise(Puppet::ParseError, "camelcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?

    value = arguments[0]
    klass = value.class

    unless [Array, String].include?(klass)
      raise(Puppet::ParseError, 'camelcase(): Requires either array or string to work with')
    end

    result = if value.is_a?(Array)
               # Numbers in Puppet are often string-encoded which is troublesome ...
               value.map { |i| i.is_a?(String) ? i.split('_').map { |e| e.capitalize }.join : i }
             else
               value.split('_').map { |e| e.capitalize }.join
             end

    return result
  end
end

# vim: set ts=2 sw=2 et :
<commit_msg>(PUP-8603) Add note to camelcase() that function is now in puppet.<commit_after>#
#  camelcase.rb
#  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.
#
module Puppet::Parser::Functions
  newfunction(:camelcase, :type => :rvalue, :doc => <<-DOC
    Converts the case of a string or all strings in an array to camel case.

    Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
    will be used instead of this function.
  DOC
             ) do |arguments|

    raise(Puppet::ParseError, "camelcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?

    value = arguments[0]
    klass = value.class

    unless [Array, String].include?(klass)
      raise(Puppet::ParseError, 'camelcase(): Requires either array or string to work with')
    end

    result = if value.is_a?(Array)
               # Numbers in Puppet are often string-encoded which is troublesome ...
               value.map { |i| i.is_a?(String) ? i.split('_').map { |e| e.capitalize }.join : i }
             else
               value.split('_').map { |e| e.capitalize }.join
             end

    return result
  end
end

# vim: set ts=2 sw=2 et :

{'fraction_non_alphanumeric': 0.10984251968503937, 'fraction_numerical': 0.012992125984251968, 'mean_word_length': 2.7588757396449703, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2636578', 'n_tokens_mistral': 800, 'n_tokens_neox': 761, 'n_words': 281}