Class: MagicShelf::KindleGenWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/magicshelf/kindlegenwrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inputfileObject

Returns the value of attribute inputfile.



8
9
10
# File 'lib/magicshelf/kindlegenwrapper.rb', line 8

def inputfile
  @inputfile
end

#outputfileObject

Returns the value of attribute outputfile.



8
9
10
# File 'lib/magicshelf/kindlegenwrapper.rb', line 8

def outputfile
  @outputfile
end

Instance Method Details

#enterObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/magicshelf/kindlegenwrapper.rb', line 10

def enter()
  MagicShelf.logger.debug('enter KindleGenWrapper')

  # check parameters
  raise MagicShelf::KindleGenWrapperError.new("inputfile is not set") if @inputfile == nil
  raise MagicShelf::KindleGenWrapperError.new("outputfile is not set") if @outputfile == nil
  out, err, status = Open3.capture3("which kindlegen")
  if status.exitstatus != 0
    raise MagicShelf::KindleGenWrapperError.new("cannot execute kindlegen, is it on your PATH?")
  end

  yield
end

#processObject



24
25
26
27
28
29
# File 'lib/magicshelf/kindlegenwrapper.rb', line 24

def process()
  out, err, status = Open3.capture3("kindlegen #{@inputfile} -o #{@outputfile}")
  if status.exitstatus != 0
    raise MagicShelf::KindleGenWrapperError.new("kindlegen exited with #{status.exitstatus}: \n" + out + "\n" + err)
  end
end