Class: DocverterServer::Runner::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/docverter-server/runner/base.rb

Direct Known Subclasses

Conversion, Calibre, PDF, Pandoc

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory, input_filename = nil, options = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
# File 'lib/docverter-server/runner/base.rb', line 9

def initialize(directory, input_filename=nil, options={})
  @directory = directory
  @input_filename = input_filename
  @options = options
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



7
8
9
# File 'lib/docverter-server/runner/base.rb', line 7

def directory
  @directory
end

#input_filenameObject (readonly)

Returns the value of attribute input_filename.



7
8
9
# File 'lib/docverter-server/runner/base.rb', line 7

def input_filename
  @input_filename
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/docverter-server/runner/base.rb', line 7

def options
  @options
end

Instance Method Details

#generate_output_filename(extension) ⇒ Object



19
20
21
# File 'lib/docverter-server/runner/base.rb', line 19

def generate_output_filename(extension)
  "output.#{SecureRandom.hex(10)}.#{extension}"
end

#runObject



15
16
17
# File 'lib/docverter-server/runner/base.rb', line 15

def run
  raise "implement in subclass"
end

#run_command(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/docverter-server/runner/base.rb', line 23

def run_command(options)
  p options
  output = ""
  cmd = Shellwords.join(options) + " 2>&1"
  p cmd
  IO.popen(cmd) do |io|
    output = io.read
  end
  if $?.exitstatus != 0
    raise DocverterServer::CommandError.new(output)
  end
end

#with_manifestObject



36
37
38
39
40
# File 'lib/docverter-server/runner/base.rb', line 36

def with_manifest
  Dir.chdir(directory) do
    yield DocverterServer::Manifest.load_file("manifest.yml")
  end
end