Class: SRS::CLI::DoExercise
- Inherits:
-
Object
- Object
- SRS::CLI::DoExercise
- Defined in:
- lib/srs/cli/do-exercise.rb
Instance Method Summary collapse
Instance Method Details
#help ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/srs/cli/do-exercise.rb', line 63 def help() puts <<-EOF srs do-exercise <id> Runs the exercise defined in <id> EOF end |
#run!(arguments) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/srs/cli/do-exercise.rb', line 4 def run!(arguments) if not SRS::Workspace.initialised? then puts "Current directory is not an SRS Workspace" return 3 end sha1 = arguments.shift sha1_start = sha1[0..1] sha1_rest = sha1[2..-1] datafile = "exercises/#{sha1_start}/#{sha1_rest}" if not File.exists?(datafile) then puts "No content with that ID exists" return 4 end headers = {} = "" File.open(datafile, "r") do |file| while( line = file.gets() ) do if line.strip.empty? then break end key, *val = line.split(':').map{|e| e.strip} headers[key] = val.join(':') end = file.read end runModel(sha1, headers, ) end |
#runModel(sha1, headers, metadata) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/srs/cli/do-exercise.rb', line 38 def runModel(sha1, headers, ) if not headers.has_key?("Model") then puts "Exercise #{sha1} has no model!\n" return nil end modelclass = headers.delete("Model") begin require "./models/#{modelclass}" rescue LoadError begin require "srs/models/#{modelclass}" rescue LoadError puts "Couldn't find model #{modelclass}." return nil end end model = SRS::Models.const_get(modelclass.to_sym).new score = model.run(headers, ) return score end |