Module: Parasort

Defined in:
lib/parasort.rb,
lib/parasort/version.rb

Defined Under Namespace

Classes: Atom, Compound, Molecule

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.each(lines, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/parasort.rb', line 10

def each(lines, &block)
  tempdir = File.join('/tmp', Time.now.strftime('%Y%m%d_%H%M%S'))
  FileUtils.mkdir(tempdir)

  compound = Compound.new(tempdir)
  lines.each_slice(Atom::SIZE).each_with_index do |ls, i|
    ls.sort!
    dest = File.join(tempdir, "#{i}_#{i}")
    File.open(dest, 'w'){ |f| f.puts ls }
    compound.add(0, Atom.new(dest))
  end
  compound.pack!

  compound.each(&block)
end