<commit_before>module EVEApi
  class Request
    attr_accessor :data
    attr_accessor :result
    attr_accessor :response

    def initialize(response=nil)
      @response = response
      raise 'No such method' if response.status == 404
      @data = parse_xml
      @result = self.parse_result
      raise error if error
    end

    def error
      data['eveapi'].has_key?('error') ? data['eveapi']['error'] : false
    end

    def parse_xml
      Crack::XML.parse(response.body)
    end

    def parse_result
      begin
        data['eveapi']['result']['rowset']['row']
      rescue NoMethodError
        data['eveapi']['result']
      rescue TypeError
        output = {}
        data['eveapi']['result']['rowset'].each do |r|
          output.merge!({ r['name'].underscore.to_sym => r['row'] })
        end
        output
      end
    end
  end
end<commit_msg>Hash handling<commit_after>module EVEApi
  class Request
    attr_accessor :data
    attr_accessor :result
    attr_accessor :response

    def initialize(response=nil)
      @response = response
      raise 'No such method' if response.status == 404
      @data = parse_xml
      @result = convert_hash_keys(self.parse_result)
      raise error if error
    end

    def error
      data['eveapi'].has_key?('error') ? data['eveapi']['error'] : false
    end

    def parse_xml
      Crack::XML.parse(response.body)
    end

    def parse_result
      begin
        data['eveapi']['result']['rowset']['row']
      rescue NoMethodError
        case data['eveapi']['result']
        when Hash
          data['eveapi']['result']
          data['eveapi']['result'].each_value do |v|
            v.process_rows if v.is_a?(Hash)
          end
        else
          data['eveapi']['result']
        end
      rescue TypeError
        output = {}
        data['eveapi']['result']['rowset'].each do |r|
          output.merge!({ r['name'].underscore.to_sym => r['row'] })
        end
        output
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12474849094567404, 'fraction_numerical': 0.0030181086519114686, 'mean_word_length': 2.2767710049423395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1739312', 'n_tokens_mistral': 597, 'n_tokens_neox': 585, 'n_words': 138}