A code autograder for student homework submissions
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

48 lignes
1.2 KiB

  1. require 'time'
  2. module KGrader
  3. def self.parse_args(raw, range, 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 < range.begin
  28. raise ArgumentError, "too many arguments" if args.size > range.end
  29. args[range.end - 1] = nil unless args.size == range.end
  30. return args, options
  31. end
  32. def self.current_semester(format)
  33. season = Time.now.strftime('%m').to_i <= 6 ? 'sp' : 'fa'
  34. case format
  35. when 'faspYY'
  36. season + Time.now.strftime('%y')
  37. when 'faspYYYY'
  38. season + Time.now.strftime('%Y')
  39. else
  40. raise ConfigError, "unknown semester format: #{format}"
  41. end
  42. end
  43. end