<commit_before>
module Prophecy

  class Manifest

    attr_accessor :items

    def initialize(book)
      @items = []
      @dir = File.expand_path(File.join(book.build_dir, 'OEBPS'))
      Dir[File.join(@dir, '**/*')].each do |f|
        next if File.directory?(f)
        next if File.fnmatch('content.opf*', File.basename(f))
        @items << ManifestItem.new(book, @dir, f)
      end
    end

    def find_by_filename(filename)
      @items.select{|i| File.basename(i.path) == File.basename(filename) }.first.href
    end

  end

  class ManifestItem

    attr_reader :href, :id, :path, :dir

    def initialize(book, dir, itempath)
      @book = book
      @dir = Pathname.new(File.expand_path(dir))
      @path = Pathname.new(File.expand_path(itempath))

      @href = @path.relative_path_from(@dir)

      if File.basename(@path.to_s) == 'toc.ncx'
        @id = 'ncx'
      elsif !book.cover_image.nil? && File.basename(book.cover_image) == File.basename(itempath)
        @id = 'cover-image'
      else
        @id = self.chapter_id || @href.to_s.downcase.gsub(/[^a-z0-9-]/, '-').gsub(/--+/, '-')
      end
    end

    def chapter_id
      ret = @book.chapters.select{|ch| ch.render_path == @path.to_s }.first
      ret.id if ret
    end

    def media_type
      ret = ""
      # first, use the known list
      ext = File.extname(@path)
      types = {
        '.ncx' => 'application/x-dtbncx+xml',
        '.ttf' => 'application/x-font-ttf',
      }
      if types.has_key?(ext)
        ret = types[ext]
      end
      # if not, ask from MIME::Types
      ret = MIME::Types.type_for(File.basename(@path)).first.to_s if ret == ""
      if ret == ""
        warn "Can't determine media type for: #{@path}"
        raise "Unknown Media Type"
      end

      ret
    end

    def to_s
      @path.to_s
    end

  end

end<commit_msg>fix otf media type<commit_after>
module Prophecy

  class Manifest

    attr_accessor :items

    def initialize(book)
      @items = []
      @dir = File.expand_path(File.join(book.build_dir, 'OEBPS'))
      Dir[File.join(@dir, '**/*')].each do |f|
        next if File.directory?(f)
        next if File.fnmatch('content.opf*', File.basename(f))
        @items << ManifestItem.new(book, @dir, f)
      end
    end

    def find_by_filename(filename)
      @items.select{|i| File.basename(i.path) == File.basename(filename) }.first.href
    end

  end

  class ManifestItem

    attr_reader :href, :id, :path, :dir

    def initialize(book, dir, itempath)
      @book = book
      @dir = Pathname.new(File.expand_path(dir))
      @path = Pathname.new(File.expand_path(itempath))

      @href = @path.relative_path_from(@dir)

      if File.basename(@path.to_s) == 'toc.ncx'
        @id = 'ncx'
      elsif !book.cover_image.nil? && File.basename(book.cover_image) == File.basename(itempath)
        @id = 'cover-image'
      else
        @id = self.chapter_id || @href.to_s.downcase.gsub(/[^a-z0-9-]/, '-').gsub(/--+/, '-')
      end
    end

    def chapter_id
      ret = @book.chapters.select{|ch| ch.render_path == @path.to_s }.first
      ret.id if ret
    end

    def media_type
      ret = ""
      # first, use the known list
      ext = File.extname(@path)
      types = {
        '.ncx' => 'application/x-dtbncx+xml',
        '.ttf' => 'application/x-font-ttf',
        '.otf' => 'application/vnd.ms-opentype',
      }
      if types.has_key?(ext)
        ret = types[ext]
      end
      # if not, ask from MIME::Types
      ret = MIME::Types.type_for(File.basename(@path)).first.to_s if ret == ""
      if ret == ""
        warn "Can't determine media type for: #{@path}"
        raise "Unknown Media Type"
      end

      ret
    end

    def to_s
      @path.to_s
    end

  end

end
{'fraction_non_alphanumeric': 0.15189535504538174, 'fraction_numerical': 0.0010678056593699946, 'mean_word_length': 2.210796915167095, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1325646', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1330, 'n_words': 278}