<commit_before>require 'uri_template'

module CrystalForge
  class WebServer
    class Route < DocumentParser::SimpleRoute
      def matches?(env)
        env['REQUEST_METHOD'].downcase == method.downcase &&
        path_matches?(env['PATH_INFO'])
      end

      def response
        [proto_response.name, proto_headers, [proto_response.body]]
      end

      private

      def path_matches?(path)
        tpl.extract(path) != nil
      end

      def tpl
        URITemplate.new(uri_template)
      end

      def action
        resource.actions.find { |a| a.method == method }
      end

      def proto_response
        action.examples.first.responses.first
      end

      def proto_headers
        proto_response.headers.collection.map do |hashy|
          [hashy[:name], hashy[:value]]
        end.to_h
      end
    end
  end
end<commit_msg>backwards compatibility fix for 1.9.3 and 2.0.0<commit_after>require 'uri_template'

module CrystalForge
  class WebServer
    class Route < DocumentParser::SimpleRoute
      def matches?(env)
        env['REQUEST_METHOD'].downcase == method.downcase &&
        path_matches?(env['PATH_INFO'])
      end

      def response
        [proto_response.name, proto_headers, [proto_response.body]]
      end

      private

      def path_matches?(path)
        tpl.extract(path) != nil
      end

      def tpl
        URITemplate.new(uri_template)
      end

      def action
        resource.actions.find { |a| a.method == method }
      end

      def proto_response
        action.examples.first.responses.first
      end

      def proto_headers
        proto_response.headers.collection.reduce({}) do |headers, hashy|
          headers.merge(hashy[:name] => hashy[:value])
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09060022650056625, 'fraction_numerical': 0.0033975084937712344, 'mean_word_length': 2.206896551724138, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '5092067', 'n_tokens_mistral': 530, 'n_tokens_neox': 515, 'n_words': 114}