class EPUBInfo::Models::TableOfContents

Attributes

manifest[RW]
ncx[RW]
parser[RW]
spine[RW]

Public Class Methods

new(parser) click to toggle source
# File lib/epubinfo/models/table_of_contents.rb, line 7
def initialize(parser)
  document = parser.metadata_document
  document_type = parser.metadata_type

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

Public Instance Methods

document() click to toggle source
# File lib/epubinfo/models/table_of_contents.rb, line 29
def document
  @toc_document ||= load_toc_file.remove_namespaces!
end
path() click to toggle source
# 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
resources() click to toggle source
# File lib/epubinfo/models/table_of_contents.rb, line 25
def resources
  @resources ||= Resource.new(self)
end
type() click to toggle source
# File lib/epubinfo/models/table_of_contents.rb, line 21
def type
  spine.first.attr('toc')
end

Private Instance Methods

load_toc_file() click to toggle source
# File lib/epubinfo/models/table_of_contents.rb, line 52
def load_toc_file
  Nokogiri::XML(parser.zip_file.read(path))
end