Class: EpubTools::AddChapters
- Inherits:
-
Object
- Object
- EpubTools::AddChapters
- Includes:
- Loggable
- Defined in:
- lib/epub_tools/add_chapters.rb
Overview
Moves new chapters into an unpacked EPUB
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ AddChapters
constructor
Initializes the class.
-
#run ⇒ Array<String>
It works like this: - First, the *.xhtml files are moved from
chapters_dir
over toepub_dir
- Then, new entries will be added to the manifest and spine of the EPUB’spackage.opf
file.
Methods included from Loggable
Constructor Details
#initialize(options = {}) ⇒ AddChapters
Initializes the class
19 20 21 22 23 24 25 26 27 |
# File 'lib/epub_tools/add_chapters.rb', line 19 def initialize( = {}) @chapters_dir = File.([:chapters_dir] || './chapters') @epub_dir = File.([:oebps_dir] || './epub/OEBPS') @opf_file = File.join(@epub_dir, 'package.opf') @nav_file = File.join(@epub_dir, 'nav.xhtml') @verbose = [:verbose] || false validate_directories! end |
Instance Method Details
#run ⇒ Array<String>
It works like this:
-
First, the *.xhtml files are moved from
chapters_dir
over toepub_dir
-
Then, new entries will be added to the manifest and spine of the EPUB’s
package.opf
file. It will sort the files by extracting the chapter number. -
Finally, it will update the
nav.xhtml
file with the new chapters. Note that if there’s a file namedchapter_0.xhtml
, it will be added to thenav.xhtml
as the Prologue.
36 37 38 39 40 41 42 |
# File 'lib/epub_tools/add_chapters.rb', line 36 def run moved_files = move_chapters update_package_opf(moved_files) update_nav_xhtml(moved_files) moved_files.each { |f| log("Moved: #{f}") } moved_files end |