<commit_before>module Opencnam
  module Util
    private

    def parse_response_date(date_string)
      DateTime.iso8601(date_string).to_time
    rescue ArgumentError
      nil
    end

    def process_response(response, name_only)
      if response.kind_of?(Net::HTTPOK)
        return { :name => response.body } if name_only

        # Parse JSON to Hash
        hash = JSON.parse(response.body, :symbolize_names => true)

        # Convert hash[:created] and hash[:updated] from String to Time
        hash.merge({ :created => parse_response_date(hash[:created]),
                     :updated => parse_response_date(hash[:updated]), })
      else
        raise OpencnamError.new response.message
      end
    end
  end
end<commit_msg>Refactor and remove large if block in Opencnam::Util#process_response<commit_after>module Opencnam
  module Util
    private

    def parse_response_date(date_string)
      DateTime.iso8601(date_string).to_time
    rescue ArgumentError
      nil
    end

    def process_response(resp, name_only)
      raise OpencnamError.new resp.message unless resp.kind_of? Net::HTTPOK
      return { :name => resp.body } if name_only

      # Parse JSON to Hash
      hash = JSON.parse(resp.body, :symbolize_names => true)

      # Convert hash[:created] and hash[:updated] from String to Time
      hash.merge({ :created => parse_response_date(hash[:created]),
                   :updated => parse_response_date(hash[:updated]), })
    end
  end
end
{'fraction_non_alphanumeric': 0.08998646820027063, 'fraction_numerical': 0.005412719891745603, 'mean_word_length': 2.944, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4501694', 'n_tokens_mistral': 436, 'n_tokens_neox': 424, 'n_words': 107}