CSC/ECE 517 Fall 2016/E1673. Refactor question type.rb
Background
Expertiza is an open source software to create reusable learning objects through peer review. It also supports team projects, and the submission of almost any document type, including URLs and wiki pages. It has following features:
- Enables students working together in a class and a topic
- Enables studnets to do peer review and improve both him/her and others' learn experience
Reason for Refractor
The purpose of this work is to rewrite part of the codes in the Criterion.rb, Scale.rb, Checkbox.rb, Dropdown.rb, Text_response.rb, Text_area.rb, Text_field.rb. This is because some of codes have bad writing sytle, or not followingg OO language rules, which confuse others to understand these code. The detail of the requirements are list below:
- Line is too long
- Some code found in other location and should put them in the parent class
- Method has too many lines
- Some of the code will cause security risk
- Using the old style validations
- Using a lower efficent way to do the loop
All of these requirements are based on a analysis software called code climate
Code Changes
text_field.rb
Although it increase the number of classes, the length of function decrease and it's easy to read than before
1. Short the long line
2. Improve security by safe_join
3. Short long method
text_response.rb
It makes codes more readable. We also choose safe_join instead of html_safe to prevent security risks. However, we must use html_safe to keep the character encoding.
1. Use new style validations
2. Short the long line
3. Improve security by safe_join
4. Short long method
scale.rb
1. Use each loop instead of for loop
2. Short the long line
3. Use safe_join to be more security
4. Delete the code similar with other file and put the duplicate into parent class.
5. Modify some method that is too long
checkbox.rb
1. Short the long line
2. Modify some method that is too long
3. Use safe_join to be more security