Class: EPUBInfo::Models::TableOfContents
- Inherits:
-
Object
- Object
- EPUBInfo::Models::TableOfContents
- Defined in:
- lib/epubinfo/models/table_of_contents.rb
Instance Attribute Summary collapse
-
#manifest ⇒ Object
Returns the value of attribute manifest.
-
#ncx ⇒ Object
Returns the value of attribute ncx.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#spine ⇒ Object
Returns the value of attribute spine.
Instance Method Summary collapse
- #document ⇒ Object
-
#initialize(parser) ⇒ TableOfContents
constructor
A new instance of TableOfContents.
- #path ⇒ Object
- #resources ⇒ Object
- #type ⇒ Object
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 = .new(self) self.parser = parser end |
Instance Attribute Details
#manifest ⇒ Object
Returns the value of attribute manifest.
46 47 48 |
# File 'lib/epubinfo/models/table_of_contents.rb', line 46 def manifest @manifest end |
#ncx ⇒ Object
Returns the value of attribute ncx.
49 50 51 |
# File 'lib/epubinfo/models/table_of_contents.rb', line 49 def ncx @ncx end |
#parser ⇒ Object
Returns the value of attribute parser.
47 48 49 |
# File 'lib/epubinfo/models/table_of_contents.rb', line 47 def parser @parser end |
#spine ⇒ Object
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
#document ⇒ Object
29 30 31 |
# File 'lib/epubinfo/models/table_of_contents.rb', line 29 def document @toc_document ||= load_toc_file.remove_namespaces! end |
#path ⇒ Object
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 |
#resources ⇒ Object
25 26 27 |
# File 'lib/epubinfo/models/table_of_contents.rb', line 25 def resources @resources ||= Resource.new(self) end |
#type ⇒ Object
21 22 23 |
# File 'lib/epubinfo/models/table_of_contents.rb', line 21 def type spine.first.attr('toc') end |