Sha256: 85d53edf4a76bf0bdbd9d867dcdc1a81f79dc5f239f42e7f814664946c559837

Contents?: true

Size: 936 Bytes

Versions: 2

Compression:

Stored size: 936 Bytes

Contents

module EPUBInfo
  class Parser
    attr_accessor :path, :metadata_document

    def self.parse(path)
      epubinfo = EPUBInfo::Parser.new
      epubinfo.path = path
      epubinfo
    end

    def metadata_document
      @metadata_document ||= load_metadata_file
    end

    def drm_protected?
      load_epub if @zipfile.nil?
      @drm_protected ||= !!@zipfile.find_entry('META-INF/rights.xml')
    end

    private

    def load_epub
      @zipfile = Zip::ZipFile.open(@path)
    end

    def load_root_file
      load_epub if @zipfile.nil?
      @root_document = Nokogiri::XML(@zipfile.read('META-INF/container.xml'))
    end

    def metadata_path
      load_root_file if @root_document.nil?
      @root_document.css('container rootfiles rootfile:first-child').attribute('full-path').content
    end

    def load_metadata_file
      load_epub if @zipfile.nil?
      Nokogiri::XML(@zipfile.read(metadata_path))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
epubinfo-0.3.1 lib/epubinfo/parser.rb
epubinfo-0.3.0 lib/epubinfo/parser.rb