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.

grade.rb 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. module CryptCheck
  2. module Grade
  3. def grade
  4. @grade ||= calculate_grade
  5. end
  6. GRADES = %i(A+ A B+ B C+ C D E F G V T X)
  7. GRADE_STATUS = {
  8. :'A+' => :best,
  9. A: :best,
  10. :'B+' => :great,
  11. B: :great,
  12. :'C+' => :good,
  13. C: :good,
  14. D: nil,
  15. E: :warning,
  16. F: :error,
  17. G: :critical,
  18. V: :critical,
  19. T: :critical,
  20. X: :critical
  21. }
  22. STATUS_GRADES = {
  23. critical: :G,
  24. error: :F,
  25. warning: :E,
  26. default: :D,
  27. good: :C,
  28. great: :B,
  29. best: :A
  30. }
  31. def grade_status
  32. GRADE_STATUS.fetch self.grade, :unknown
  33. end
  34. private
  35. def calculate_grade
  36. return :V unless self.valid?
  37. return :T unless self.trusted?
  38. states = self.states
  39. states = State.collect { |s| [s, State.state(states, s)] }.to_h
  40. State::BADS.each do |s|
  41. return STATUS_GRADES[s] if states[s]
  42. end
  43. grade = STATUS_GRADES[:default]
  44. State::GOODS.each do |s|
  45. state = states[s]
  46. return grade if state == false
  47. grade = STATUS_GRADES[s]
  48. return grade if state == :some
  49. grade = "#{grade}+".to_sym
  50. end
  51. grade
  52. end
  53. end
  54. end