Class: FreeLing::Analyzer::ProcessWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/freeling/analyzer/process_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, output_fd, env = {}) ⇒ ProcessWrapper

Returns a new instance of ProcessWrapper.



10
11
12
13
14
15
# File 'lib/freeling/analyzer/process_wrapper.rb', line 10

def initialize(command, output_fd, env={})
  @command = command
  @output_fd = output_fd
  @env = env
  @error_log = nil
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



8
9
10
# File 'lib/freeling/analyzer/process_wrapper.rb', line 8

def command
  @command
end

#envObject

Returns the value of attribute env.



8
9
10
# File 'lib/freeling/analyzer/process_wrapper.rb', line 8

def env
  @env
end

#error_logObject

Returns the value of attribute error_log.



8
9
10
# File 'lib/freeling/analyzer/process_wrapper.rb', line 8

def error_log
  @error_log
end

#output_fdObject

Returns the value of attribute output_fd.



8
9
10
# File 'lib/freeling/analyzer/process_wrapper.rb', line 8

def output_fd
  @output_fd
end

Instance Method Details

#closeObject



39
40
41
# File 'lib/freeling/analyzer/process_wrapper.rb', line 39

def close
  close_process
end

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/freeling/analyzer/process_wrapper.rb', line 17

def run
  @error_log = nil

  Enumerator.new do |yielder|
    open_process

    if @stdout.nil?
      run_process
    end

    while line = @stdout.gets
      line.chomp!
      yielder << line
    end

    @stdout.close_read
    @error_log = @stderr.read
    @write_thr.join
    close_process
  end
end