Class: EpubWorm::Extractors::NcxNavigation
- Inherits:
-
Object
- Object
- EpubWorm::Extractors::NcxNavigation
show all
- Extended by:
- Base
- Defined in:
- lib/epub_worm/extractors/ncx_navigation.rb
Constant Summary
Constants included
from Base
Base::DEFAULT_NS
Class Method Summary
collapse
Methods included from Base
as_xml, element_at, elements_at, extended, ns, ns_entry, open_opf, text_at
Class Method Details
.as_navigation(nav_point) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/epub_worm/extractors/ncx_navigation.rb', line 41
def self.as_navigation(nav_point)
::EpubWorm::Navigation.new(
title: text_at(nav_point, "ncx:navLabel/ncx:text"),
reference: element_at(nav_point, "ncx:content")["src"],
children: elements_at(nav_point, "ncx:navPoint").map { |e| as_navigation(e) }
)
end
|
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/epub_worm/extractors/ncx_navigation.rb', line 11
def self.(path)
open_opf(path) do |opf_doc, opf_file_path, zip_file|
toc_file_path = ::File.join(::File.dirname(opf_file_path), toc_reference(opf_doc))
toc_file = zip_file.find_entry toc_file_path
raise ::EpubWorm::Error, "toc file not found" unless toc_file
toc_doc = as_xml toc_file
nav_points = elements_at(toc_doc, "//ncx:navMap/ncx:navPoint")
build_navigation nav_points
end
end
|