Class: Astromapper::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/astromapper/exporter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_dir, options) ⇒ Exporter

Returns a new instance of Exporter.



11
12
13
14
# File 'lib/astromapper/exporter.rb', line 11

def initialize(root_dir, options)
  @root_dir = root_dir
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/astromapper/exporter.rb', line 9

def options
  @options
end

#root_dirObject

Returns the value of attribute root_dir.



8
9
10
# File 'lib/astromapper/exporter.rb', line 8

def root_dir
  @root_dir
end

Class Method Details

.run(root_dir, options) ⇒ Object



3
4
5
6
# File 'lib/astromapper/exporter.rb', line 3

def self.run(root_dir, options)
  exporter = new(root_dir, options)
  exporter.export!
end

Instance Method Details

#configObject



60
61
62
# File 'lib/astromapper/exporter.rb', line 60

def config
  Astromapper.config(root_dir)
end

#export!Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/astromapper/exporter.rb', line 20

def export!
  helper = root_dir.join("config/helper.rb")
  load(helper) if helper.exist?
  exported = []

  sector = Builder::Sector.constitute(root_dir)

  sector.to_file

  # export_pdf  = [nil, "pdf"].include?(options[:only])
  # export_html = [nil, "html", "mobi", "epub"].include?(options[:only])
  # export_epub = [nil, "mobi", "epub"].include?(options[:only])
  # export_mobi = [nil, "mobi"].include?(options[:only])
  # export_txt  = [nil, "txt"].include?(options[:only])

  # exported = []
  # exported << Parser::PDF.parse(root_dir) if export_pdf && Dependency.xelatex?# && Dependency.prince?
  # exported << Parser::HTML.parse(root_dir) if export_html 
  # epub_done = Parser::Epub.parse(root_dir) if export_epub
  # exported << epub_done
  # exported << Parser::Mobi.parse(root_dir) if export_mobi && epub_done && Dependency.kindlegen?
  # exported << Parser::Txt.parse(root_dir) if export_txt && Dependency.html2text?

  if exported.all?
    color = :green
    message = options[:auto] ? "exported!" : "** Map has been exported"

    # Notifier.notify(
    #   # :image   => Astromapper::ROOT.join("templates/ebook.png"),
    #   :title   => "Astromapper",
    #   :message => "Your \"#{config[:title]}\" map has been exported!"
    # )
  else
    color = :red
    message = options[:auto] ? "could not be exported!" : "** e-book couldn't be exported"
  end

  ui.say message, color
end

#uiObject



16
17
18
# File 'lib/astromapper/exporter.rb', line 16

def ui
  @ui ||= Thor::Base.shell.new
end