class Klipbook::Commands::Export

Public Instance Methods

run_command!(book_source, options) click to toggle source
# File lib/klipbook/commands/export.rb, line 4
def run_command!(book_source, options)
  exit_unless_valid_format(options)
  exit_unless_valid_output_dir(options)

  exporter(options).run!(
    books: book_source.books,
    force: options.force,
    output_dir: options.output_dir
  )
end

Private Instance Methods

exit_unless_valid_format(options) click to toggle source
# File lib/klipbook/commands/export.rb, line 30
def exit_unless_valid_format(options)
  unless ["markdown", "html", "json"].include?(options.format)
    logger.error "Error: You must specify a valid format."
    exit 127
  end
end
exit_unless_valid_output_dir(options) click to toggle source
# File lib/klipbook/commands/export.rb, line 37
def exit_unless_valid_output_dir(options)
  unless options.output_dir
    logger.error "Error: Please specify an outdir."
    exit 127
  end

  unless File.directory?(options.output_dir)
    logger.error "Error: Output directory '#{options.output_dir}' does not exist."
    exit 127
  end
end
exporter(options) click to toggle source
# File lib/klipbook/commands/export.rb, line 17
def exporter(options)
  case options.format
  when  "markdown"
    Exporters::MarkdownExporter.new(logger)
  when "html"
    Exporters::HTMLExporter.new(logger)
  when "json"
    Exporters::JSONExporter.new(logger)
  else
    raise "Unexpected format"
  end
end