<commit_before>module Cheffish
  class MergedConfig
    def initialize(*configs)
      @configs = configs
    end

    attr_reader :configs

    def [](name)
      result_configs = []
      configs.each do |config|
        value = config[name]
        if !value.nil?
          if value.respond_to?(:keys)
            result_configs << value
          elsif result_configs.size > 0
            return result_configs[0]
          else
            return value
          end
        end
      end
      if result_configs.size > 1
        MergedConfig.new(*result_configs)
      elsif result_configs.size == 1
        result_configs[0]
      else
        nil
      end
    end

    def method_missing(name)
      self[name]
    end<commit_msg>Add ability to merge arrays<commit_after>module Cheffish
  class MergedConfig
    def initialize(*configs)
      @configs = configs
      @merge_arrays = {}
    end

    attr_reader :configs
    def merge_arrays(*symbols)
      symbols.each do |symbol|
        @merge_arrays[symbol] = true
      end
    end

    def [](name)
      if @merge_arrays[name]
        configs.select { |c| !c[name].nil? }.collect_concat { |c| c[name] }
      else
        result_configs = []
        configs.each do |config|
          value = config[name]
          if !value.nil?
            if value.respond_to?(:keys)
              result_configs << value
            elsif result_configs.size > 0
              return result_configs[0]
            else
              return value
            end
          end
        end
        if result_configs.size > 1
          MergedConfig.new(*result_configs)
        elsif result_configs.size == 1
          result_configs[0]
        else
          nil
        end
      end
    end

    def method_missing(name)
      self[name]
    end
{'fraction_non_alphanumeric': 0.07555555555555556, 'fraction_numerical': 0.005555555555555556, 'mean_word_length': 1.613933236574746, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '3283451', 'n_tokens_mistral': 550, 'n_tokens_neox': 538, 'n_words': 127}