Class: Epub::Toc
- Inherits:
-
Object
- Object
- Epub::Toc
- Defined in:
- lib/epub-reader/toc.rb
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(tocfile, reader) ⇒ Toc
constructor
A new instance of Toc.
- #pages ⇒ Object
Constructor Details
#initialize(tocfile, reader) ⇒ Toc
Returns a new instance of Toc.
4 5 6 7 8 9 10 |
# File 'lib/epub-reader/toc.rb', line 4 def initialize(tocfile, reader) @tocfile = tocfile @reader = reader @file = @reader.file @content = get_toc_content @xml = Nokogiri::XML(@content).remove_namespaces! end |
Instance Method Details
#content ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/epub-reader/toc.rb', line 12 def content if ncx? if has_toc? ncx_to_html else spine_to_html end else @content end end |
#pages ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/epub-reader/toc.rb', line 24 def pages points = @xml.css("ncx navMap navPoint") items = @reader.package.reading_order if ncx? && has_toc? && points.size > 1 points.map do |point| title = point.css('navLabel > text').first.text file_path = @reader.package.relative_content_path + point.css('content').attr('src').to_s Page.new(title, file_path, @reader.file) end else items.map do |item| title = "" file_path = @reader.package.relative_content_path + item.attr('href').to_s Page.new(title, file_path, @reader.file) end end end |