Class: EPUB::Parser::OCF

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

Constructor Details

#initialize(container) ⇒ OCF

Returns a new instance of OCF.

[View source]

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

[View source]

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

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

Instance Method Details

#parseObject

[View source]

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

[View source]

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 = XMLDocument.new(xml)
  doc.each_element_by_xpath "/ocf:container/ocf:rootfiles/ocf:rootfile", EPUB::NAMESPACES do |elem|
    rootfile = EPUB::OCF::Container::Rootfile.new
    rootfile.full_path = Addressable::URI.parse(elem.attribute_with_prefix('full-path'))
    rootfile.media_type = elem.attribute_with_prefix('media-type')
    container.rootfiles << rootfile
  end

  container
end

#parse_encryption(content) ⇒ Object

[View source]

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

[View source]

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

[View source]

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

def (content)
  doc = XMLDocument.new(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.attribute_with_prefix('unique-identifier'), 'metadata')
end

#parse_rights(content) ⇒ Object

[View source]

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

[View source]

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

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