Class: EPUBInfo::Models::TableOfContents

Inherits:
Object
  • Object
show all
Defined in:
lib/epubinfo/models/table_of_contents.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ TableOfContents

Returns a new instance of TableOfContents.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/epubinfo/models/table_of_contents.rb', line 7

def initialize(parser)
  document = parser.
  document_type = parser.

  return if document.nil? || !document_type.eql?("application/oebps-package+xml")
  document.remove_namespaces!
   = document.css('metadata')
  self.spine = .xpath('//spine')
  self.manifest = .xpath('//manifest')
  self.ncx   = Navigation.new(self)
  self.parser = parser
end

Instance Attribute Details

#manifestObject

Returns the value of attribute manifest.



46
47
48
# File 'lib/epubinfo/models/table_of_contents.rb', line 46

def manifest
  @manifest
end

#ncxObject

Returns the value of attribute ncx.



49
50
51
# File 'lib/epubinfo/models/table_of_contents.rb', line 49

def ncx
  @ncx
end

#parserObject

Returns the value of attribute parser.



47
48
49
# File 'lib/epubinfo/models/table_of_contents.rb', line 47

def parser
  @parser
end

#spineObject

Returns the value of attribute spine.



48
49
50
# File 'lib/epubinfo/models/table_of_contents.rb', line 48

def spine
  @spine
end

Instance Method Details

#documentObject



29
30
31
# File 'lib/epubinfo/models/table_of_contents.rb', line 29

def document
  @toc_document ||= load_toc_file.remove_namespaces!
end

#pathObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/epubinfo/models/table_of_contents.rb', line 33

def path
  @toc_path ||= begin
    spine_path = nil
    if spine && !spine.empty?
      toc_id = spine[0]['toc']
      toc_ncx = manifest.xpath("item[@id = '#{toc_id}']").first.attr('href')
      spine_path = parser.zip_file.entries.map { |p| p.name }.select { |s| s.match(toc_ncx) }.first
    end
    spine_path
  end

end

#resourcesObject



25
26
27
# File 'lib/epubinfo/models/table_of_contents.rb', line 25

def resources
  @resources ||= Resource.new(self)
end

#typeObject



21
22
23
# File 'lib/epubinfo/models/table_of_contents.rb', line 21

def type
  spine.first.attr('toc')
end