Class: StdoutLineBuffer
- Inherits:
-
Object
- Object
- StdoutLineBuffer
- Defined in:
- lib/audit/lib/parser/stdout_line_buffer.rb
Instance Method Summary collapse
-
#initialize(connection) ⇒ StdoutLineBuffer
constructor
A new instance of StdoutLineBuffer.
- #on_line(&block) ⇒ Object
Constructor Details
#initialize(connection) ⇒ StdoutLineBuffer
Returns a new instance of StdoutLineBuffer.
7 8 9 10 11 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 37 38 |
# File 'lib/audit/lib/parser/stdout_line_buffer.rb', line 7 def initialize(connection) #puts "DEBUG: StdoutLineBuffer on connection #{connection}" @buffer = "" connection.on_stdout do|msg| #puts "DEBUG: Buffer: '#{msg}'" @buffer += msg #puts "DEBUG: Buffer size: #{msg.length}, #{@buffer.length}" if @buffer[-1] == "\n" || @buffer =~ /\n$/ then #puts "DEBUG: endline detected using Array Class or using regexp" lines = @buffer.split("\n") @buffer = "" elsif @buffer =~ /^.+$/ then #puts "DEBUG: endline detected using regexp" lines = @buffer.split("\n") @buffer = "" else #puts "DEBUG: no endline detected" #puts "DEBUG: hexa buffer: #{@buffer.inspect}" #@buffer.each_byte {|c| print c, ' ' } #puts "\n" lines = @buffer.split("\n") @buffer = lines[-1] lines = lines[0 ... -1] end lines.each do|line| #puts "DEBUG: line: '#{line}'" @handler.call(line + "\n") unless @handler.nil? end end end |
Instance Method Details
#on_line(&block) ⇒ Object
40 41 42 |
# File 'lib/audit/lib/parser/stdout_line_buffer.rb', line 40 def on_line(&block) @handler = block end |