Class: FieldReports::ExecProxy
- Defined in:
- lib/field_reports/exec_proxy.rb
Instance Method Summary collapse
-
#initialize(exe_path, cwd, loglevel, logout) ⇒ ExecProxy
constructor
A new instance of ExecProxy.
- #parse(pdf) ⇒ Object
- #render(param) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(exe_path, cwd, loglevel, logout) ⇒ ExecProxy
Returns a new instance of ExecProxy.
9 10 11 12 13 14 |
# File 'lib/field_reports/exec_proxy.rb', line 9 def initialize(exe_path, cwd, loglevel, logout) @exe_path = exe_path @cwd = cwd @loglevel = loglevel @logout = logout end |
Instance Method Details
#parse(pdf) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/field_reports/exec_proxy.rb', line 47 def parse(pdf) begin Open3.popen3(@exe_path, "parse", "-", :chdir=>@cwd) {|i, o, e, t| i.write(pdf) i.close @logout.write(e.read) if t.value.exitstatus != 0 then raise RuntimeError, format("Exit Code = %d", t.value.exitstatus) end return JSON.parse(o.read) } rescue => exn raise ReportsError, (exn) end end |
#render(param) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/field_reports/exec_proxy.rb', line 30 def render(param) begin body = param.is_a?(Hash) ? param.to_json : param Open3.popen3(@exe_path, "render", "-l", @loglevel.to_s, "-", "-", :chdir=>@cwd) {|i, o, e, t| i.write(body) i.close @logout.write(e.read) if t.value.exitstatus != 0 then raise RuntimeError, format("Exit Code = %d", t.value.exitstatus) end return o.read } rescue => exn raise ReportsError, (exn) end end |
#version ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/field_reports/exec_proxy.rb', line 16 def version begin Open3.popen3(@exe_path, "version") {|i, o, e, t| @logout.write(e.read) if t.value.exitstatus != 0 then raise RuntimeError, format("Exit Code = %d", t.value.exitstatus) end return o.read.strip } rescue => exn raise ReportsError, (exn) end end |