Class: Pmux::TextPartitioner
- Inherits:
-
Object
- Object
- Pmux::TextPartitioner
- Defined in:
- lib/pmux/mapper.rb
Instance Method Summary collapse
- #close ⇒ Object
- #emit(data) ⇒ Object
-
#initialize(ifbase, num_r, options = {}) ⇒ TextPartitioner
constructor
A new instance of TextPartitioner.
Constructor Details
#initialize(ifbase, num_r, options = {}) ⇒ TextPartitioner
Returns a new instance of TextPartitioner.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/pmux/mapper.rb', line 125 def initialize ifbase, num_r, ={} @ifbase = ifbase @num_r = num_r @ifiles = (0..(num_r-1)).map {|n| open("#{ifbase}-#{n}", 'w')} @rbuf = '' if (sep = [:separator]) @separator_re = Regexp.new sep else @separator_re = /\t/ end end |
Instance Method Details
#close ⇒ Object
148 149 150 |
# File 'lib/pmux/mapper.rb', line 148 def close @ifiles.each {|io| io.close} end |
#emit(data) ⇒ Object
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/pmux/mapper.rb', line 137 def emit data @rbuf << data while true break unless @rbuf =~ /\n/ line, s = @rbuf.split /^/, 2 key, = line.split @separator_re, 2 @ifiles[key.hash % @num_r].write line @rbuf.replace(s || '') end end |