Class: EpubTools::EpubInitializer

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/epub_tools/epub_initializer.rb

Overview

Sets up a basic empty EPUB directory structure with the basic files created:

  • mimetype

  • container.xml

  • title.xhtml as a title page

  • package.opf

  • nav.xhtml as a table of contents

  • style.css a basic style inherited from the repo

  • cover image (optionally)

Instance Method Summary collapse

Methods included from Loggable

#log

Constructor Details

#initialize(options = {}) ⇒ EpubInitializer

Initializes the class

Parameters:

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

    Configuration options

Options Hash (options):

  • :title (String)

    Book title (required)

  • :author (String)

    Book author (required)

  • :destination (String)

    Target directory for the EPUB files (required)

  • :cover_image (String)

    Optional path to the cover image

  • :verbose (Boolean)

    Whether to print progress to STDOUT (default: false)



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

def initialize(options = {})
  @title = options.fetch(:title)
  @author = options.fetch(:author)
  @destination = File.expand_path(options.fetch(:destination))
  @uuid = "urn:uuid:#{SecureRandom.uuid}"
  @modified = Time.now.utc.iso8601
  @cover_image_path = options[:cover_image]
  @cover_image_fname = nil
  @cover_image_media_type = nil
  @verbose = options[:verbose] || false
end

Instance Method Details

#runObject

Creates the empty ebook and returns the directory



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/epub_tools/epub_initializer.rb', line 38

def run
  create_structure
  write_mimetype
  write_title_page
  write_container
  write_cover if @cover_image_path
  write_package_opf
  write_nav
  write_style
  log "Created empty ebook structure at: #{@destination}"
  @destination
end