<commit_before># encoding: UTF-8

require 'rack'

module Spontaneous::Plugins::Page
  module Formats
    module ClassMethods
      def formats(*formats)
        return format_list if formats.nil? or formats.empty?
        set_formats(formats)
      end

      def format_list
        @formats ||= supertype_formats
      end

      def mime_types
        @mime_types ||= supertype_mimetypes
      end

      def add_format(new_format)
        format = define_format(new_format)
        format_list.push(format)
      end

      def set_formats(formats)
        formats = formats.flatten
        mime_types.clear
        format_list.clear
        formats.map do |format|
          format_list.push define_format(format)
        end
      end

      def define_format(format)
        mime_type = nil
        if format.is_a?(Hash)
          mime_type = format.values.first
          format = format.keys.first
          mime_types[format.to_sym] = mime_type
        else
          mime_type = ::Rack::Mime.mime_type("#{Spontaneous::DOT}#{format}", nil)
        end
        raise Spontaneous::UnknownFormatException.new(format) unless mime_type
        format.to_sym
      end

      def supertype_formats
        supertype? && supertype.respond_to?(:formats) ? supertype.formats.dup : [:html]
      end

      def supertype_mimetypes
        supertype? && supertype.respond_to?(:mime_types) ? supertype.mime_types.dup : {}
      end

      def default_format
        formats.first
      end

      def provides_format?(format)
        format = (format || :html).to_sym
        formats.include?(format)
      end

      def mime_type(format)
        if mime_types && mime_types.key?(format)
          mime_types[format]
        else
          ::Rack::Mime.mime_type("#{Spontaneous::DOT}#{format}")
        end<commit_msg>What the hell was I thinking?<commit_after># encoding: UTF-8

require 'rack'

module Spontaneous::Plugins::Page
  module Formats
    module ClassMethods
      def formats(*formats)
        return format_list if formats.nil? or formats.empty?
        set_formats(formats)
      end

      def format_list
        @formats ||= supertype_formats
      end

      def mime_types
        @mime_types ||= supertype_mimetypes
      end

      def add_format(new_format)
        format = define_format(new_format)
        format_list.push(format)
      end

      def set_formats(formats)
        formats = formats.flatten
        mime_types.clear
        format_list.clear
        formats.map do |format|
          format_list.push define_format(format)
        end
      end

      def define_format(format)
        mime_type = nil
        if format.is_a?(Hash)
          mime_type = format.values.first
          format = format.keys.first
          mime_types[format.to_sym] = mime_type
        else
          mime_type = ::Rack::Mime.mime_type(".#{format}", nil)
        end
        raise Spontaneous::UnknownFormatException.new(format) unless mime_type
        format.to_sym
      end

      def supertype_formats
        supertype? && supertype.respond_to?(:formats) ? supertype.formats.dup : [:html]
      end

      def supertype_mimetypes
        supertype? && supertype.respond_to?(:mime_types) ? supertype.mime_types.dup : {}
      end

      def default_format
        formats.first
      end

      def provides_format?(format)
        format = (format || :html).to_sym
        formats.include?(format)
      end

      def mime_type(format)
        if mime_types && mime_types.key?(format)
          mime_types[format]
        else
          ::Rack::Mime.mime_type(".#{format}")
        end
{'fraction_non_alphanumeric': 0.08771444382955175, 'fraction_numerical': 0.0005534034311012728, 'mean_word_length': 2.1654991243432575, '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': '2543293', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1104, 'n_words': 216}