Sha256: 871ad0e068d486fdecdd14675b3e2e75db2ea0f327d8992e721d5578415cb84c

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

module Mandy
  class TestRunner
    def initialize(job=Mandy::Job.default)
      @job = job
    end
    
    def map(input, output_stream=StringIO.new(''), &blk)
      input = input_from_array(input) if input.is_a?(Array)
      input_stream = StringIO.new(input.to_s)
      @job.run_map(input_stream, output_stream, &blk)
      output_stream.rewind
      output_stream
    end
    
    def reduce(input, output_stream=StringIO.new(''), &blk)
      input = input_from_hash(input) if input.is_a?(Hash)
      input_stream = StringIO.new(input.to_s)
      @job.run_reduce(input_stream, output_stream, &blk)
      output_stream.rewind
      output_stream
    end
    
    private
    
    def input_from_array(input)
      input.join("\n")
    end
    
    def input_from_hash(input)
      output = []
      input.each do |key, values|
        output << "#{key}\t#{values}" and next unless values.is_a?(Array)
        values.each { |value| output << "#{key}\t#{value}" }
      end
      input_from_array(output.sort)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trafficbroker-mandy-0.1.0 lib/test_runner.rb
trafficbroker-mandy-0.1.1 lib/test_runner.rb