Class: EpubTools::CompileBook

Inherits:
Object
  • Object
show all
Defined in:
lib/epub_tools/compile_book.rb

Overview

Orchestrates extraction, splitting, validation, and packaging of book EPUBs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, author:, source_dir:, cover_image: nil, output_file: nil, build_dir: nil, verbose: false) ⇒ CompileBook

title: String, author: String, source_dir: path to input epubs cover_image: optional path to cover image, output_file: filename for final epub build_dir: optional working directory for intermediate files



14
15
16
17
18
19
20
21
22
# File 'lib/epub_tools/compile_book.rb', line 14

def initialize(title:, author:, source_dir:, cover_image: nil, output_file: nil, build_dir: nil, verbose: false)
  @title       = title
  @author      = author
  @source_dir  = source_dir
  @cover_image = cover_image
  @output_file = output_file || default_output_file
  @build_dir   = build_dir || File.join(Dir.pwd, '.epub_tools_build')
  @verbose     = verbose
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



9
10
11
# File 'lib/epub_tools/compile_book.rb', line 9

def author
  @author
end

#build_dirObject (readonly)

Returns the value of attribute build_dir.



9
10
11
# File 'lib/epub_tools/compile_book.rb', line 9

def build_dir
  @build_dir
end

#cover_imageObject (readonly)

Returns the value of attribute cover_image.



9
10
11
# File 'lib/epub_tools/compile_book.rb', line 9

def cover_image
  @cover_image
end

#output_fileObject (readonly)

Returns the value of attribute output_file.



9
10
11
# File 'lib/epub_tools/compile_book.rb', line 9

def output_file
  @output_file
end

#source_dirObject (readonly)

Returns the value of attribute source_dir.



9
10
11
# File 'lib/epub_tools/compile_book.rb', line 9

def source_dir
  @source_dir
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/epub_tools/compile_book.rb', line 9

def title
  @title
end

#verboseObject (readonly)

Returns the value of attribute verbose.



9
10
11
# File 'lib/epub_tools/compile_book.rb', line 9

def verbose
  @verbose
end

Instance Method Details

#runObject

Run the full compile workflow



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/epub_tools/compile_book.rb', line 25

def run
  clean_build_dir
  prepare_dirs
  extract_xhtmls
  split_xhtmls
  validate_sequence
  initialize_epub
  add_chapters
  pack_epub
  log "Done. Output EPUB: #{File.expand_path(output_file)}"
  clean_build_dir
end