Class: GoogleCodeJam::Runner
- Inherits:
-
Object
- Object
- GoogleCodeJam::Runner
- Defined in:
- lib/googlecodejam/runner.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Runner
constructor
A new instance of Runner.
Constructor Details
#initialize(options = {}) ⇒ Runner
Returns a new instance of Runner.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/googlecodejam/runner.rb', line 4 def initialize(={}) instance = self.initialize_from_path([:source]) input = open([:input]).read [:output] ||= [:input].gsub('.in', ".out") num, *lines = input.split("\n") output = lines.each_with_index.inject("") do |r, (n, i)| begin r + (i+1==1 ? "" : "\n") + "Case ##{i+1}: #{instance.run(n)}" rescue => e puts e.backtrace raise "Line: #{n.inspect}" end end.strip File.open([:output], 'w+') {|f| f.write(output) } end |