Class: EpubTools::CompileBook

Inherits:
Object
  • Object
show all
Includes:
Loggable
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

Methods included from Loggable

#log

Constructor Details

#initialize(options = {}) ⇒ CompileBook

Initializes the class

Parameters:

  • options (Hash) (defaults to: {})

    Configuration options

Options Hash (options):

  • :title (String)

    Book title (required)

  • :author (String)

    Book author (required)

  • :source_dir (String)

    Path of the input epubs (required)

  • :cover_image (String)

    Optional path to the cover image

  • :output_file (String)

    Filename for the final epub (default: [title].epub)

  • :build_dir (String)

    Optional working directory for intermediate files

  • :verbose (Boolean)

    Whether to print progress to STDOUT (default: false)



38
39
40
41
42
43
44
45
46
# File 'lib/epub_tools/compile_book.rb', line 38

def initialize(options = {})
  @title       = options.fetch(:title)
  @author      = options.fetch(:author)
  @source_dir  = options.fetch(:source_dir)
  @cover_image = options[:cover_image]
  @output_file = options[:output_file] || default_output_file
  @build_dir   = options[:build_dir] || File.join(Dir.pwd, '.epub_tools_build')
  @verbose     = options[:verbose] || false
end

Instance Attribute Details

#authorObject (readonly)

Book author



17
18
19
# File 'lib/epub_tools/compile_book.rb', line 17

def author
  @author
end

#build_dirObject (readonly)

Optional working directory for intermediate files



25
26
27
# File 'lib/epub_tools/compile_book.rb', line 25

def build_dir
  @build_dir
end

#cover_imageObject (readonly)

Optional path to the cover image



21
22
23
# File 'lib/epub_tools/compile_book.rb', line 21

def cover_image
  @cover_image
end

#output_fileObject (readonly)

Filename for the final epub



23
24
25
# File 'lib/epub_tools/compile_book.rb', line 23

def output_file
  @output_file
end

#source_dirObject (readonly)

Path of the input epubs



19
20
21
# File 'lib/epub_tools/compile_book.rb', line 19

def source_dir
  @source_dir
end

#titleObject (readonly)

Book title



15
16
17
# File 'lib/epub_tools/compile_book.rb', line 15

def title
  @title
end

#verboseObject (readonly)

Whether to print progress to STDOUT



27
28
29
# File 'lib/epub_tools/compile_book.rb', line 27

def verbose
  @verbose
end

Instance Method Details

#runObject

Run the full compile workflow



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/epub_tools/compile_book.rb', line 49

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