Class: Lf::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/lf/stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, output, option) ⇒ Stream

Returns a new instance of Stream.



5
6
7
# File 'lib/lf/stream.rb', line 5

def initialize(input, output, option)
  @input, @output, @option = input, output, option
end

Instance Method Details

#processObject



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

def process
  loop do
    line = @input.gets
    break unless line
    row = Lf::Row.new(line)
    row = @option.filters.reduce(row) { |a, e| a && e.apply(a) }
    @output.puts(row.to_s(@option[:format])) if row
    @output.flush unless @option[:buffered]
  end
rescue Interrupt
  @output.flush
end