Sha256: 67d5401b8154a2d365f29c5ef8475f4bf93b3df6f5c7f337cf85fe2027d55532
Contents?: true
Size: 1.84 KB
Versions: 4
Compression:
Stored size: 1.84 KB
Contents
require 'epub/constants' require 'epub/ocf' require 'epub/ocf/physical_container' require 'zipruby' 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 ::Zip::Error, ::Errno::ENOENT, OpenURI::HTTPError 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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
epub-parser-0.2.4 | lib/epub/parser/ocf.rb |
epub-parser-0.2.3 | lib/epub/parser/ocf.rb |
epub-parser-0.2.2 | lib/epub/parser/ocf.rb |
epub-parser-0.2.1 | lib/epub/parser/ocf.rb |