Skip to content

Instantly share code, notes, and snippets.

@oncomouse
Last active December 9, 2020 15:39
Show Gist options
  • Save oncomouse/ef14ad4d6a13b55b63745b1e2092370f to your computer and use it in GitHub Desktop.
Save oncomouse/ef14ad4d6a13b55b63745b1e2092370f to your computer and use it in GitHub Desktop.
Create grade rubrics for students given a CSV file exported from Banner and a blank rubric
# frozen_string_literal: true
require 'fileutils'
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = 'Usage: dirs.rb [options]'
opts.on('-a', '--assignment ASSIGNMENT', 'Assignment Name') { |v| options[:assignment] = v }
opts.on('-s', '--semester SEMESTER', 'Semester') { |v| options[:semester] = v }
opts.on('-f', '--force', 'Overwrite an existing project') { |v| options[:force] = v }
end.parse!
raise StandardError, "Cannot find file #{options[:assignment]}.docx" unless File.exist? "./#{options[:assignment]}.docx"
raise StandardError, "Cannot find file ../#{options[:semester]}.csv" unless File.exist? "../#{options[:semester]}.csv"
project_dir = "./#{options[:semester]}-#{options[:assignment]}"
if Dir.exist?(project_dir) && !options[:force]
puts 'That project has already been created. Use --force to override this check.'
exit
end
Dir.mkdir project_dir unless Dir.exist? project_dir
csv = IO.readlines("../#{options[:semester]}.csv")
key = csv.shift.split(/,\s*/)
lname_index = key.find_index('LAST NAME')
fname_index = key.find_index('FIRST NAME')
csv.each do |csv_line|
csv_line = csv_line.split(/,\s*/)
name = "./#{project_dir}/#{csv_line[fname_index]} #{csv_line[lname_index]}"
Dir.mkdir(name) unless Dir.exist? name
FileUtils.cp("./#{options[:assignment]}.docx", "#{name}/#{csv_line[fname_index]} #{csv_line[lname_index]}.docx")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment