Class: EpubTools::SplitChapters
- Inherits:
-
Object
- Object
- EpubTools::SplitChapters
- Includes:
- Loggable
- Defined in:
- lib/epub_tools/split_chapters.rb
Overview
Takes a Google Docs generated, already extracted from their EPUB, XHTML files with multiple chapters and it:
-
Extracts classes using StyleFinder
-
Looks for tags that say something like Chapter XX or Prologue and splits the text there
-
Creates new chapter_XX.xhtml files that are cleaned using XHTMLCleaner
-
Saves those files to
output_dir
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SplitChapters
constructor
Initializes the class.
-
#run ⇒ Array<String>
Runs the splitter.
Methods included from Loggable
Constructor Details
#initialize(options = {}) ⇒ SplitChapters
Initializes the class
26 27 28 29 30 31 32 |
# File 'lib/epub_tools/split_chapters.rb', line 26 def initialize( = {}) @input_file = .fetch(:input_file) @book_title = .fetch(:book_title) @output_dir = [:output_dir] || './chapters' @output_prefix = [:output_prefix] || 'chapter' @verbose = [:verbose] || false end |
Instance Method Details
#run ⇒ Array<String>
Runs the splitter
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/epub_tools/split_chapters.rb', line 36 def run # Prepare output dir FileUtils.mkdir_p(@output_dir) # Read the doc raw_content = doc = Nokogiri::HTML(raw_content) # Find Style Classes StyleFinder.new({ file_path: @input_file, verbose: @verbose }).run chapters = extract_chapters(doc) write_chapter_files(chapters) end |