Module: CommandWrap::OpenOffice

Defined in:
lib/command_wrap/open_office.rb,
lib/command_wrap/open_office/server.rb

Defined Under Namespace

Modules: Server

Class Method Summary collapse

Class Method Details

.convert(*args) ⇒ Object

Converts the given source to target

Possible parameters: source (path to source file) + target (path to target file) content (content of source file) + source extension (extension of source file) + target extension (extension of target file)



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/command_wrap/open_office.rb', line 12

def self.convert (*args)
    if args.length == 2
        source = args[0]
        target = args[1]
    elsif args.length == 3
        source = CommandWrap.temp(args[1])
        target = CommandWrap.temp(args[2])
        # Save Content
        File.open(source, 'w') do |file|
            file.write args[0]
        end
    else
        raise ArgumentError.new('wrong number of arguments')
    end
    command = File.dirname(__FILE__) + "/../../bin/DocumentConverter.py"
    result = `#{CommandWrap::Config::OpenOffice.python} #{command}  #{source} #{target} #{CommandWrap::Config::OpenOffice.port}`
    raise result unless result.strip == ''

    if args.length == 3
        result = IO.read(target)
        File.delete(source) if File.writable?(source)
        File.delete(target) if File.writable?(target)
        result
    end
end