Class: CodeJam::Runner
- Inherits:
-
Object
- Object
- CodeJam::Runner
- Defined in:
- lib/codejam/runner.rb
Instance Attribute Summary collapse
-
#testcases ⇒ Object
readonly
Returns the value of attribute testcases.
Instance Method Summary collapse
-
#initialize(input, caseclass) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
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
#testcases ⇒ Object (readonly)
Returns the value of attribute testcases.
4 5 6 |
# File 'lib/codejam/runner.rb', line 4 def testcases @testcases end |
Instance Method Details
#run ⇒ Object
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 |