Home > Navigation

Traversing

Example to show tree of Table of Contents:

nav = book.manifest.navs.first.content_document # => EPUB::ContentDocument::Navigation
toc = nav.toc # => EPUB::ContentDocument::Navigation::Navigation
toc_tree = ''
toc.traverse do |item, depth|
  item # => EPUB::ContentDocument::Navigation::Item
  depth # => Integer
  toc_tree << "#{' ' * depth * 2}#{item.text}\n"
end
puts toc_tree
THE CONTENTS
  SECTION IV FAIRY STORIES

NOTE: This API is not stable.