class Klipbook::Commands::Exporters::Exporter

Public Class Methods

new(logger=Logger.new) click to toggle source
# File lib/klipbook/commands/exporters/exporter.rb, line 5
def initialize(logger=Logger.new)
  @logger = logger
end

Public Instance Methods

run!(books:, force:, output_dir:) click to toggle source
# File lib/klipbook/commands/exporters/exporter.rb, line 9
def run!(books:, force:, output_dir:)
  @logger.info "Using output directory: #{output_dir}"

  books.each do |book|
    export_book(book, output_dir, force)
  end
end

Private Instance Methods

export_book(book, output_dir, force) click to toggle source
# File lib/klipbook/commands/exporters/exporter.rb, line 19
def export_book(book, output_dir, force)
  filename = filename_for_book(book)
  filepath = File.join(output_dir, filename)

  if !force && File.exist?(filepath)
    @logger.info "- Skipping #{filename}"
    return
  end

  @logger.info "+ Writing #{filename}"

  File.open(filepath, 'w') do |f|
    f.write render_contents(book)
  end
end
extension() click to toggle source
# File lib/klipbook/commands/exporters/exporter.rb, line 39
def extension
  raise "Implement me"
end
filename_for_book(book) click to toggle source
# File lib/klipbook/commands/exporters/exporter.rb, line 43
def filename_for_book(book)
  "#{book.title.gsub(/[:,\/!?]/, "")}.#{extension}"
end
render_contents(book) click to toggle source
# File lib/klipbook/commands/exporters/exporter.rb, line 35
def render_contents(book)
  raise "Implement me"
end