CSC/ECE 517 Spring 2021 - E2107. Refactor grades controller.rb
Introduction
Problem Statement
Expertiza has a functionality that allows students and instructors to receive and give grades, respectively. This functionality is implemented with the grades_controller.rb . This controller violates some essential Rails design principles including having too much calculation and having methods' names that violate Ruby naming convention.
Project Task
Here are the refactoring steps needed to be taken in order to fix the grades_controller.rb .
- Create a new private method to encapsulate the population of the view model for all the necessary data (lines 102-107).
- Simplify the logic surrounding the error flashing. The nested logic seems unnecessary (lines 190-192).
- In line 300:
- Increase readability by fixing whitespace according to the common Ruby Programming guidelines.
- Return is not needed here.
- Remove space between ‘!’ and its argument.
- Use meaningful variable names and break up the expression.
- Move these functions into grades_helper.rb and change their names to be more Ruby-like:
- calculate_all_penalties
- calculate_penalty_attributes
- mean (also cease the usage of the assignment)
- calculate_average_vector
- build_score_vector
- Remove_negative_scores_and_build_charts