Class: MergeRows

Inherits:
Join
  • Object
show all
Defined in:
lib/streaming_join/merge_rows.rb

Instance Method Summary collapse

Methods inherited from Join

#initialize, #null_left, #null_right, #report

Constructor Details

This class inherits a constructor from Join

Instance Method Details

#output(key) ⇒ Object



4
5
6
7
8
9
# File 'lib/streaming_join/merge_rows.rb', line 4

def output key
  report 'keys'

  o = "#{key}#{@sep_out}#{@join.join(@sep_out)}"
  block_given? ? (yield o) : (puts o)
end

#process_stream(input = STDIN) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/streaming_join/merge_rows.rb', line 11

def process_stream(input = STDIN)
  last_key = key = nil
  @join = []

  input.each do |line|
    key, value = line.chomp.split(@sep_in, 2)

    if last_key and last_key != key
      output last_key
      @join = []
    end

    @join << value
    last_key = key
  end

  output last_key if key
end