Sha256: f9c7adcee3409012f9d8a0f20b9ad17abe7dd2bf2ef6c6bc13a6289e78dc5a53
Contents?: true
Size: 1.99 KB
Versions: 1
Compression:
Stored size: 1.99 KB
Contents
require 'epub/constants' require 'epub/ocf' require 'epub/ocf/physical_container' require 'nokogiri' module EPUB class Parser class OCF include Utils DIRECTORY = 'META-INF' class << self def parse(container) new(container).parse end end def initialize(container) @container = container @ocf = EPUB::OCF.new end def parse EPUB::OCF::MODULES.each do |m| begin data = @container.read(File.join(DIRECTORY, "#{m}.xml")) @ocf.__send__ "#{m}=", __send__("parse_#{m}", data) rescue EPUB::OCF::PhysicalContainer::NoEntry, ::Errno::ENOENT, OpenURI::HTTPError rescue => error raise error unless (Object.const_defined? :Zip and ::Zip.const_defined? :Error and error.kind_of? ::Zip::Error) end end @ocf end def parse_container(xml) container = EPUB::OCF::Container.new doc = Nokogiri.XML(xml) doc.xpath('/ocf:container/ocf:rootfiles/ocf:rootfile', EPUB::NAMESPACES).each do |elem| rootfile = EPUB::OCF::Container::Rootfile.new rootfile.full_path = Addressable::URI.parse(extract_attribute(elem, 'full-path')) rootfile.media_type = extract_attribute(elem, 'media-type') container.rootfiles << rootfile end container end def parse_encryption(content) encryption = EPUB::OCF::Encryption.new encryption.content = content encryption end def parse_manifest(content) warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE end def parse_metadata(content) warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE end def parse_rights(content) warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE end def parse_signatures(content) warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
epub-parser-0.2.5 | lib/epub/parser/ocf.rb |