<commit_before>require 'tomogram_routing'
require 'json-schema'
require 'fitting/storage/yaml_file'
require 'fitting/request'
require 'fitting/response'

module Fitting
  class Documentation
    class << self
      def try_on(date, env_request, env_response)
        request = Request.new(env_request, tomogram)
        request.valid! if request.validate?
        response = Response.new(env_response, request.schema)
        response.valid! if response.validate?
        add_storage(location(date), request, response)
      end

      private

      def add_storage(location, request, response)
        Fitting::Storage::YamlFile.push(
          location,
          'request' => MultiJson.dump(request.to_hash),
          'response' => MultiJson.dump(response.to_hash)
        )
      end

      def tomogram
        @tomogram ||= TomogramRouting::Tomogram.craft(Fitting.configuration.tomogram)
      end

      def location(date)
        date.inspect.to_s.split('(').last.split(')').first
      end
    end
  end
end
<commit_msg>fix location<commit_after>require 'tomogram_routing'
require 'json-schema'
require 'fitting/storage/yaml_file'
require 'fitting/request'
require 'fitting/response'

module Fitting
  class Documentation
    class << self
      def try_on(date, env_request, env_response)
        request = Request.new(env_request, tomogram)
        request.valid! if request.validate?
        response = Response.new(env_response, request.schema)
        response.valid! if response.validate?
        add_storage(location(date), request, response)
      end

      private

      def add_storage(location, request, response)
        Fitting::Storage::YamlFile.push(
          location,
          'request' => MultiJson.dump(request.to_hash),
          'response' => MultiJson.dump(response.to_hash)
        )
      end

      def tomogram
        @tomogram ||= TomogramRouting::Tomogram.craft(Fitting.configuration.tomogram)
      end

      def location(date)
        name = date.inspect.to_s
        if name.split('(').size > 1
          name.split('(').last.split(')').first[2..-1]
        else
          name.split(' ')[3][2..-3]
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10973936899862825, 'fraction_numerical': 0.0027434842249657062, 'mean_word_length': 2.6588628762541804, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '1754937', 'n_tokens_mistral': 651, 'n_tokens_neox': 641, 'n_words': 130}