class EPUB::Parser::OCF

Constants

DIRECTORY

Public Class Methods

new(zip_archive) click to toggle source
# File lib/epub/parser/ocf.rb, line 20
def initialize(zip_archive)
  @zip = zip_archive
  @ocf = EPUB::OCF.new
end
parse(zip_archive) click to toggle source
# File lib/epub/parser/ocf.rb, line 15
def parse(zip_archive)
  new(zip_archive).parse
end

Public Instance Methods

parse() click to toggle source
# File lib/epub/parser/ocf.rb, line 25
def parse
  EPUB::OCF::MODULES.each do |m|
    begin
      file = @zip.fopen(File.join(DIRECTORY, "#{m}.xml"))
      @ocf.__send__ "#{m}=", __send__("parse_#{m}", file.read)
    rescue Zip::Error
    end
  end

  @ocf
end
parse_container(xml) click to toggle source
# File lib/epub/parser/ocf.rb, line 37
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
parse_encryption(content) click to toggle source
# File lib/epub/parser/ocf.rb, line 50
def parse_encryption(content)
  encryption = EPUB::OCF::Encryption.new
  encryption.content = content
  encryption
end
parse_manifest(content) click to toggle source
# File lib/epub/parser/ocf.rb, line 56
def parse_manifest(content)
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
end
parse_metadata(content) click to toggle source
# File lib/epub/parser/ocf.rb, line 60
def parse_metadata(content)
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
end
parse_rights(content) click to toggle source
# File lib/epub/parser/ocf.rb, line 64
def parse_rights(content)
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
end
parse_signatures(content) click to toggle source
# File lib/epub/parser/ocf.rb, line 68
def parse_signatures(content)
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
end