Class: EpubTools::SplitChapters
- Inherits:
-
Object
- Object
- EpubTools::SplitChapters
- Defined in:
- lib/epub_tools/split_chapters.rb
Instance Method Summary collapse
-
#initialize(input_file, book_title, output_dir = './chapters', output_prefix = 'chapter', verbose = false) ⇒ SplitChapters
constructor
input_file: path to the source XHTML book_title: title to use in HTML <title> tags output_dir: where to write chapter files output_prefix: filename prefix (e.g. “chapter”).
- #run ⇒ Object
Constructor Details
#initialize(input_file, book_title, output_dir = './chapters', output_prefix = 'chapter', verbose = false) ⇒ SplitChapters
input_file: path to the source XHTML book_title: title to use in HTML <title> tags output_dir: where to write chapter files output_prefix: filename prefix (e.g. “chapter”)
13 14 15 16 17 18 19 |
# File 'lib/epub_tools/split_chapters.rb', line 13 def initialize(input_file, book_title, output_dir = './chapters', output_prefix = 'chapter', verbose = false) @input_file = input_file @book_title = book_title @output_dir = output_dir @output_prefix = output_prefix @verbose = verbose end |
Instance Method Details
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/epub_tools/split_chapters.rb', line 21 def run # Prepare output dir Dir.mkdir(@output_dir) unless Dir.exist?(@output_dir) # Read the doc raw_content = read_and_strip_problematic_hr doc = Nokogiri::HTML(raw_content) # Find Style Classes TextStyleClassFinder.new(@input_file, verbose: @verbose).call chapters = extract_chapters(doc) write_chapter_files(chapters) end |