Class: EPUB::Parser::OCF

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/epub/parser/ocf.rb

Constant Summary collapse

DIRECTORY =
'META-INF'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

extract_attribute

Constructor Details

#initialize(container) ⇒ OCF

Returns a new instance of OCF.



20
21
22
23
# File 'lib/epub/parser/ocf.rb', line 20

def initialize(container)
  @container = container
  @ocf = EPUB::OCF.new
end

Class Method Details

.parse(container) ⇒ Object



15
16
17
# File 'lib/epub/parser/ocf.rb', line 15

def parse(container)
  new(container).parse
end

Instance Method Details

#parseObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/epub/parser/ocf.rb', line 25

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

#parse_container(xml) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# 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) ⇒ Object



50
51
52
53
54
# 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) ⇒ Object



56
57
58
# File 'lib/epub/parser/ocf.rb', line 56

def parse_manifest(content)
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
end

#parse_metadata(content) ⇒ Object



60
61
62
# File 'lib/epub/parser/ocf.rb', line 60

def (content)
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
end

#parse_rights(content) ⇒ Object



64
65
66
# File 'lib/epub/parser/ocf.rb', line 64

def parse_rights(content)
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
end

#parse_signatures(content) ⇒ Object



68
69
70
# File 'lib/epub/parser/ocf.rb', line 68

def parse_signatures(content)
  warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
end