Class: GradingRule
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- GradingRule
- Defined in:
- app/models/grading_rule.rb
Class Method Summary collapse
-
.format_score(course_id, raw_score) ⇒ Object
To format the score is correct format before saving into the database.
-
.get_grade_type(course_id) ⇒ Object
To get the grade type of the course, i.e.
Instance Method Summary collapse
- #default_values? ⇒ Boolean
-
#get_grade_params_for_javascript ⇒ Object
To get the grade parameters for calculating earned grade and final grade in the javascript.
-
#letter_grades ⇒ Object
To get all of the valid letter grades.
-
#validate_letter_grade(raw_score) ⇒ Object
To perform letter grade validation for the given score.
-
#validate_score(raw_score) ⇒ Object
To perform validation for the given score by the grade type.
Class Method Details
.format_score(course_id, raw_score) ⇒ Object
To format the score is correct format before saving into the database.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/grading_rule.rb', line 80 def self.format_score (course_id, raw_score) raw_score=raw_score.to_s grading_rule = GradingRule.find_by_course_id(course_id) if grading_rule.nil? return raw_score elsif grading_rule.grade_type=="weights" && raw_score.end_with?("%") return raw_score.split("%")[0] else return raw_score end end |
.get_grade_type(course_id) ⇒ Object
To get the grade type of the course, i.e. it is points or weights
93 94 95 96 97 98 99 100 |
# File 'app/models/grading_rule.rb', line 93 def self.get_grade_type (course_id) grading_rule = GradingRule.find_by_course_id(course_id) if grading_rule.nil? return "points" end return grading_rule.grade_type end |
Instance Method Details
#default_values? ⇒ Boolean
46 47 48 49 |
# File 'app/models/grading_rule.rb', line 46 def default_values? attribute_values = self.attributes.values attribute_values.include?(nil) end |
#get_grade_params_for_javascript ⇒ Object
To get the grade parameters for calculating earned grade and final grade in the javascript.
103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/models/grading_rule.rb', line 103 def get_grade_params_for_javascript weight_hash = [] self.course.assignments.each do |assignment| score = assignment.maximum_score if self.grade_type == "weights" score *= 0.01 end weight_hash << score end "'#{GradingRule.get_grade_type self.course_id}', #{mapping_rule.to_json}, #{weight_hash.to_json}" end |
#letter_grades ⇒ Object
To get all of the valid letter grades.
116 117 118 |
# File 'app/models/grading_rule.rb', line 116 def letter_grades @letter_grades ||= mapping_rule.keys end |
#validate_letter_grade(raw_score) ⇒ Object
To perform letter grade validation for the given score.
52 53 54 |
# File 'app/models/grading_rule.rb', line 52 def validate_letter_grade(raw_score) mapping_rule.has_key?(raw_score.to_s.upcase) end |
#validate_score(raw_score) ⇒ Object
To perform validation for the given score by the grade type
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/grading_rule.rb', line 57 def validate_score(raw_score) # allow users to skip entering grades if raw_score.nil? || raw_score.empty? return true end # allow users to enter letter grades if mapping_rule.has_key?(raw_score.to_s.upcase) return true end # return the grading type case grade_type when "points" return validate_points(raw_score) when "weights" return validate_weights(raw_score) else return false end end |