Class: EPUB::Parser::OCF

Inherits:
Object
  • Object
show all
Includes:
Metadata, 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 Metadata

#build_model, #build_unsupported_model

Methods included from Utils

extract_attribute

Constructor Details

#initialize(container) ⇒ OCF

Returns a new instance of OCF.



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

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

Class Method Details

.parse(container) ⇒ Object



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

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

Instance Method Details

#parseObject



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

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
    end
  end

  @ocf
end

#parse_container(xml) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/epub/parser/ocf.rb', line 38

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



51
52
53
54
55
# File 'lib/epub/parser/ocf.rb', line 51

def parse_encryption(content)
  encryption = EPUB::OCF::Encryption.new
  encryption.content = content
  encryption
end

#parse_manifest(content) ⇒ Object



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

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

#parse_metadata(content) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/epub/parser/ocf.rb', line 61

def (content)
  doc = Nokogiri.XML(content)
  unless multiple_rendition_metadata?(doc)
    warn "Not implemented: #{self.class}##{__method__}" if $VERBOSE
     = EPUB::OCF::UnknownFormatMetadata.new
    .content = content
    return 
  end
  super(doc.root, doc.root['unique-identifier'], 'metadata')
end

#parse_rights(content) ⇒ Object



72
73
74
# File 'lib/epub/parser/ocf.rb', line 72

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

#parse_signatures(content) ⇒ Object



76
77
78
# File 'lib/epub/parser/ocf.rb', line 76

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