Class: CodeJam::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/codejam/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, caseclass) ⇒ Runner

Returns a new instance of Runner.



6
7
8
9
10
# File 'lib/codejam/runner.rb', line 6

def initialize(input, caseclass)
  num, *lines = input.split("\n")
  raise "Invalid input: wrong number of testcases" if num.to_i != lines.size
  @testcases = lines.map {|n| caseclass.new(n)}
end

Instance Attribute Details

#testcasesObject (readonly)

Returns the value of attribute testcases.



4
5
6
# File 'lib/codejam/runner.rb', line 4

def testcases
  @testcases
end

Instance Method Details

#runObject



12
13
14
15
16
# File 'lib/codejam/runner.rb', line 12

def run
  testcases.each_with_index.inject("") do |r, (n, i)|
    r + (i+1==1 ? "" : "\n") + "Case ##{i+1}: #{n.run}"
  end
end