<commit_before>module Cb
  module Responses

    class Errors
      attr_reader :parsed

      def initialize(raw_response_hash, raise_on_error = true)
        @response     = raw_response_hash
        @should_raise = raise_on_error
        @parsed       = parsed_errors
      end

      private
      attr_reader :response, :should_raise

      def parsed_errors
        return Array.new unless response.respond_to?(:map)
        errors = response.map { |key, value| parsed_error(key, value) }.flatten
        raise ApiResponseError.new(errors.to_s) if errors.any? && should_raise
        errors
      end

      def parsed_error(key, value)
        if hashy_errors?(key, value)
          value.values
        elsif error_array?(key, value)
          value
        else
          Array.new
        end
      end

      def hashy_errors?(key, value)
        key.downcase == 'errors' && value.is_a?(Hash)
      end

      def error_array?(key, value)
        (key.downcase == 'error' || key.downcase == 'errors') && value.is_a?(Array)
      end

      def method_missing(method, *args, &block)
        parsed.send(method, *args, &block)
      end
    end

  end
end
<commit_msg>changed to_s to join<commit_after>module Cb
  module Responses

    class Errors
      attr_reader :parsed

      def initialize(raw_response_hash, raise_on_error = true)
        @response     = raw_response_hash
        @should_raise = raise_on_error
        @parsed       = parsed_errors
      end

      private
      attr_reader :response, :should_raise

      def parsed_errors
        return Array.new unless response.respond_to?(:map)
        errors = response.map { |key, value| parsed_error(key, value) }.flatten
        raise ApiResponseError.new(errors.join(',')) if errors.any? && should_raise
        errors
      end

      def parsed_error(key, value)
        if hashy_errors?(key, value)
          value.values
        elsif error_array?(key, value)
          value
        else
          Array.new
        end
      end

      def hashy_errors?(key, value)
        key.downcase == 'errors' && value.is_a?(Hash)
      end

      def error_array?(key, value)
        (key.downcase == 'error' || key.downcase == 'errors') && value.is_a?(Array)
      end

      def method_missing(method, *args, &block)
        parsed.send(method, *args, &block)
      end
    end

  end
end

{'fraction_non_alphanumeric': 0.09256128486897718, 'fraction_numerical': 0.0, 'mean_word_length': 2.130952380952381, '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': '4907814', 'n_tokens_mistral': 724, 'n_tokens_neox': 723, 'n_words': 173}