<commit_before>module OpenXml
  module Parts
    class ContentTypes < OpenXml::Part
      attr_reader :defaults, :overrides

      def self.parse(xml)
        document = Nokogiri(xml)
        self.new.tap do |part|
          document.css("Default").each do |default|
            part.add_default default["Extension"], default["ContentType"]
          end
          document.css("Override").each do |default|
            part.add_override default["PartName"], default["ContentType"]
          end
        end
      end

      def initialize(defaults={}, overrides={})
        @defaults = defaults
        @overrides = overrides
      end

      def add_default(extension, content_type)
        defaults[extension] = content_type
      end

      def add_override(part_name, content_type)
        overrides[part_name] = content_type
      end

      def to_xml
        build_xml do |xml|
          xml.Types(xmlns: "http://schemas.openxmlformats.org/package/2006/content-types") {
            defaults.each { |extension, content_type| xml.Default("Extension" => extension, "ContentType" => content_type) }
            overrides.each { |part_name, content_type| xml.Override("PartName" => part_name, "ContentType" => content_type) }
          }
        end
      end

    end
  end
end<commit_msg>[refactor] Added required defaults for content_types (2m)<commit_after>module OpenXml
  module Parts
    class ContentTypes < OpenXml::Part
      attr_reader :defaults, :overrides

      REQUIRED_DEFAULTS = {
        "xml" => "application/xml",
        "rels" => "application/vnd.openxmlformats-package.relationships+xml"
      }.freeze

      def self.parse(xml)
        document = Nokogiri(xml)
        self.new.tap do |part|
          document.css("Default").each do |default|
            part.add_default default["Extension"], default["ContentType"]
          end
          document.css("Override").each do |default|
            part.add_override default["PartName"], default["ContentType"]
          end
        end
      end

      def initialize(defaults={}, overrides={})
        @defaults = REQUIRED_DEFAULTS.merge(defaults)
        @overrides = overrides
      end

      def add_default(extension, content_type)
        defaults[extension] = content_type
      end

      def add_override(part_name, content_type)
        overrides[part_name] = content_type
      end

      def to_xml
        build_xml do |xml|
          xml.Types(xmlns: "http://schemas.openxmlformats.org/package/2006/content-types") {
            defaults.each { |extension, content_type| xml.Default("Extension" => extension, "ContentType" => content_type) }
            overrides.each { |part_name, content_type| xml.Override("PartName" => part_name, "ContentType" => content_type) }
          }
        end
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.10660980810234541, 'fraction_numerical': 0.0031982942430703624, 'mean_word_length': 2.4624846248462484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 24}, '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': '6628003', 'n_tokens_mistral': 818, 'n_tokens_neox': 793, 'n_words': 169}