From eab1d5a5ff8c286c0965d41b7568066a2c75ec14 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 31 Mar 2016 02:01:46 -0500 Subject: [PATCH] Mock up assignment class. --- lib/kgrader.rb | 1 + lib/kgrader/assignment.rb | 15 +++++++++++++++ lib/kgrader/cli.rb | 5 +---- lib/kgrader/course.rb | 10 ++++++---- lib/kgrader/errors.rb | 3 +++ lib/kgrader/filesystem.rb | 24 ++++++++++++++++-------- lib/kgrader/task.rb | 7 ++++--- 7 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 lib/kgrader/assignment.rb diff --git a/lib/kgrader.rb b/lib/kgrader.rb index 708fdfc..de89b03 100644 --- a/lib/kgrader.rb +++ b/lib/kgrader.rb @@ -1,3 +1,4 @@ +require_relative 'kgrader/assignment' require_relative 'kgrader/cli' require_relative 'kgrader/course' require_relative 'kgrader/errors' diff --git a/lib/kgrader/assignment.rb b/lib/kgrader/assignment.rb new file mode 100644 index 0000000..ee22e50 --- /dev/null +++ b/lib/kgrader/assignment.rb @@ -0,0 +1,15 @@ +module KGrader + class Assignment + attr_reader :name + + def initialize(filesystem, course, name) + @fs = filesystem + @course = course + @name = name + + @config = @fs.load @fs.assignment(@course.name, @name) + rescue FilesystemError + raise AssignmentError, "unknown assignment: #{name}" + end + end +end diff --git a/lib/kgrader/cli.rb b/lib/kgrader/cli.rb index 203342a..4a87c3e 100644 --- a/lib/kgrader/cli.rb +++ b/lib/kgrader/cli.rb @@ -1,6 +1,3 @@ -require_relative 'course' -require_relative 'filesystem' - module KGrader class CLI @@ -65,7 +62,7 @@ module KGrader puts "#{pad}assignments:" course.assignments.each do |assignment| - puts "#{pad} - #{assignment}" + puts "#{pad} - #{assignment.name}" end end diff --git a/lib/kgrader/course.rb b/lib/kgrader/course.rb index eb79d43..1492de8 100644 --- a/lib/kgrader/course.rb +++ b/lib/kgrader/course.rb @@ -1,6 +1,3 @@ -require_relative 'roster' -require_relative 'task' - module KGrader class Course attr_reader :name @@ -11,6 +8,7 @@ module KGrader @config = @fs.load @fs.course_config(@name) @rosters = {} + @assignments = {} rescue FilesystemError raise CourseError, "unknown or invalid course: #{name}" end @@ -19,6 +17,10 @@ module KGrader @rosters[semester] ||= Roster.new @fs, self, semester end + def assignment(name) + @assignments[name] ||= Assignment.new @fs, self, name + end + def task(semester, assignment) Task.new @fs, self, semester, assignment end @@ -28,7 +30,7 @@ module KGrader end def assignments - @fs.assignments @name + @fs.assignments(@name).map! { |name| assignment name } end def current_semester diff --git a/lib/kgrader/errors.rb b/lib/kgrader/errors.rb index edb1598..34afe05 100644 --- a/lib/kgrader/errors.rb +++ b/lib/kgrader/errors.rb @@ -14,6 +14,9 @@ module KGrader class CourseError < KGraderError end + class AssignmentError < KGraderError + end + class RosterError < KGraderError end end diff --git a/lib/kgrader/filesystem.rb b/lib/kgrader/filesystem.rb index e8effa4..ce9bb6c 100644 --- a/lib/kgrader/filesystem.rb +++ b/lib/kgrader/filesystem.rb @@ -19,6 +19,8 @@ module KGrader File.join @root, 'spec' end + # ------------------------------------------------------------------------- + def course(name) File.join spec, name end @@ -27,24 +29,30 @@ module KGrader File.join course(name), '_config.yml' end - def roster(course_name, semester) - File.join desk, course_name, semester, '_roster.csv' + def assignment(courseid, name) + File.join course(courseid), name, '_config.yml' + end + + def roster(courseid, semester) + File.join desk, courseid, semester, '_roster.csv' end + # ------------------------------------------------------------------------- + def courses Dir[File.join spec, '*', ''].map! { |fn| File.basename fn } end - def assignments(course_name) - Dir[File.join course(course_name), '*', '_config.yml'].map! do |fn| - File.basename File.dirname fn - end + def assignments(courseid) + Dir[assignment courseid '*'].map! { |fn| File.basename File.dirname fn } end - def semesters(course_name) - Dir[roster course_name, '*'].map! { |fn| File.basename File.dirname fn } + def semesters(courseid) + Dir[roster courseid, '*'].map! { |fn| File.basename File.dirname fn } end + # ------------------------------------------------------------------------- + def load(path) case File.extname path when '.yml', '.yaml' diff --git a/lib/kgrader/task.rb b/lib/kgrader/task.rb index 4dc6e2b..f05a195 100644 --- a/lib/kgrader/task.rb +++ b/lib/kgrader/task.rb @@ -5,7 +5,8 @@ module KGrader @fs = filesystem @course = course @semester = semester - @assignment = assignment + + @assignment = @course.assignment assignment @students = @course.roster(@semester).students end @@ -18,7 +19,7 @@ module KGrader regrade = options.fetch(:regrade, false) # TODO - puts "Grading #{@course.name}:#{@semester} assignment #{@assignment}..." + puts "Grading #{@course.name}:#{@semester} assignment #{@assignment.name}..." puts "- students: #{students.inspect}" puts "- due: #{due}" puts "- fetch: #{fetch}" @@ -30,7 +31,7 @@ module KGrader students &= options[:students] unless options[:students].nil? # TODO - puts "Committing #{@course.name}:#{@semester} assignment #{@assignment}..." + puts "Committing #{@course.name}:#{@semester} assignment #{@assignment.name}..." puts "- students: #{students.inspect}" end end