Class: Softcover::Builders::Mobi

Inherits:
Softcover::Builder show all
Defined in:
lib/softcover/builders/mobi.rb

Constant Summary

Constants included from Utils

Utils::UNITS

Instance Attribute Summary

Attributes inherited from Softcover::Builder

#built_files, #manifest

Instance Method Summary collapse

Methods inherited from Softcover::Builder

#clean!, #initialize

Methods included from Utils

#add_highlight_class!, #as_size, #book_txt_lines, #chapter_label, #commands, #current_book, #dependency_filename, #digest, #executable, #execute, #in_book_directory?, #language_labels, #linux?, #logged_in?, #master_content, #master_filename, #master_latex_header, #mkdir, #os_x?, #path, #raw_lines, #reset_current_book!, #rm, #silence, #source, #tmpify, #unpublish_slug, #write_master_latex_file, #write_pygments_file

Constructor Details

This class inherits a constructor from Softcover::Builder

Instance Method Details

#build!(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/softcover/builders/mobi.rb', line 5

def build!(options={})
  Softcover::Builders::Epub.new.build!(options)
  filename = mobi_filename(options)
  command  = mobi_command(filename, options)
  silent   = options[:silent] || Softcover.test?
  if options[:quiet] || silent
    silence { system(command) }
  else
    system(command)
  end
  if options[:calibre]
    FileUtils.mv("ebooks/#{filename}.azw3", "ebooks/#{filename}.mobi")
    puts "MOBI saved to ebooks/#{filename}.mobi" unless silent
  end
end

#mobi_command(filename, options = {}) ⇒ Object

Returns the command for making a MOBI, based on the options.



27
28
29
30
31
32
33
# File 'lib/softcover/builders/mobi.rb', line 27

def mobi_command(filename, options={})
  if options[:calibre]
    "#{calibre} ebooks/#{filename}.epub ebooks/#{filename}.azw3"
  else
    "#{kindlegen} ebooks/#{filename}.epub"
  end
end

#mobi_filename(options = {}) ⇒ Object

Returns the filename of the MOBI (preview if necessary).



22
23
24
# File 'lib/softcover/builders/mobi.rb', line 22

def mobi_filename(options={})
  options[:preview] ? manifest.filename + '-preview' : manifest.filename
end