Module: MSWord

Defined in:
lib/msword.rb,
lib/msword/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.process(args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/msword.rb', line 22

def self.process args
  java_options = args.delete(:java_options) || "-Dfile.encoding=utf8 -Xms512m -Xmx512m -XX:MaxPermSize=256m"
  jar_path = File.join(File.dirname(__FILE__), "msword.jar")
  puts MultiJson.encode(args)
  Open3.popen3("java #{java_options} -jar #{jar_path}") do |stdin, stdout, stderr, wait_thr|
    stdin.write MultiJson.encode(args)
    stdin.close
    exit_status = wait_thr.value
    if exit_status != 0
      puts stdout.read
      puts stderr.read
    end
  end

end

.replace(input_file, output_file, pairs) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/msword.rb', line 7

def self.replace input_file, output_file, pairs
  args = {
    src: input_file,
    output: output_file,
    commands: [
      {
        command: :replace,
        args: pairs
      }
    ]
  }

  process(args)
end