<commit_before>module ActiveModel
  class Serializer
    class Fieldset
      def initialize(fields, root = nil)
        @root       = root
        @raw_fields = fields
      end

      def fields
        @fields ||= parsed_fields
      end

      def fields_for(serializer)
        key = serializer.json_key
        fields[key.to_sym] || fields[key.pluralize.to_sym]
      end

      private

      ActiveModelSerializers.silence_warnings do
        attr_reader :raw_fields, :root
      end

      def parsed_fields
        if raw_fields.is_a?(Hash)
          raw_fields.inject({}) { |h, (k, v)| h[k.to_sym] = v.map(&:to_sym); h }
        elsif raw_fields.is_a?(Array)
          if root.nil?
            raise ArgumentError, 'The root argument must be specified if the fileds argument is an array.'
          end
          hash = {}
          hash[root.to_sym] = raw_fields.map(&:to_sym)
          hash
        else
          {}
        end
      end
    end
  end
end<commit_msg>Fix typo in fieldset exception<commit_after>module ActiveModel
  class Serializer
    class Fieldset
      def initialize(fields, root = nil)
        @root       = root
        @raw_fields = fields
      end

      def fields
        @fields ||= parsed_fields
      end

      def fields_for(serializer)
        key = serializer.json_key
        fields[key.to_sym] || fields[key.pluralize.to_sym]
      end

      private

      ActiveModelSerializers.silence_warnings do
        attr_reader :raw_fields, :root
      end

      def parsed_fields
        if raw_fields.is_a?(Hash)
          raw_fields.inject({}) { |h, (k, v)| h[k.to_sym] = v.map(&:to_sym); h }
        elsif raw_fields.is_a?(Array)
          if root.nil?
            raise ArgumentError, 'The root argument must be specified if the fields argument is an array.'
          end
          hash = {}
          hash[root.to_sym] = raw_fields.map(&:to_sym)
          hash
        else
          {}
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08388074785245073, 'fraction_numerical': 0.0, 'mean_word_length': 1.7926657263751764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5922789', 'n_tokens_mistral': 608, 'n_tokens_neox': 601, 'n_words': 153}