A code autograder for student homework submissions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

  1. require 'time'
  2. module KGrader
  3. def self.parse_args(raw, num, keywords)
  4. args = []
  5. options = {}
  6. raw.each do |arg|
  7. if arg.include? '='
  8. key, val = arg.split('=', 2)
  9. key = key.to_sym
  10. unless keywords.include? key
  11. raise ArgumentError, "unknown keyword: #{key}"
  12. end
  13. options[key] = case keywords[key]
  14. when :string
  15. val
  16. when :bool
  17. %w(true yes 1 t y).include? val.downcase
  18. when :array
  19. val.split(",").map! { |x| x.strip.downcase }
  20. when :time
  21. Time.parse(val)
  22. end
  23. else
  24. args << arg
  25. end
  26. end
  27. raise ArgumentError, "too few arguments" if args.size < num
  28. raise ArgumentError, "too many arguments" if args.size > num
  29. return args, options
  30. end
  31. def self.current_semester(format)
  32. season = Time.now.strftime('%m').to_i <= 6 ? 'sp' : 'fa'
  33. case format
  34. when 'faspYY'
  35. season + Time.now.strftime('%y')
  36. when 'faspYYYY'
  37. season + Time.now.strftime('%Y')
  38. else
  39. raise ConfigError, "unknown semester format: #{format}"
  40. end
  41. end
  42. end