CSC/ECE 517 Fall 2016/E1673. Refactor question type.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 6: Line 6:
; text_field.rb
; text_field.rb
: Although it increase the number of classes, the length of function decrease and it's easy to read than before
: Although it increase the number of classes, the length of function decrease and it's easy to read than before
def view_completed_question(count, answer)
def view_completed_question(count, answer)
     if self.type == 'TextField' and self.break_before == true
     if self.type == 'TextField' and self.break_before == true
       html = '<b>' + count.to_s + ". " + self.txt + "</b>"
       html = '<b>' + count.to_s + ". " + self.txt + "</b>"
Line 17: Line 17:
     safe_join([" ".html_safe, " ".html_safe], html.html_safe)
     safe_join([" ".html_safe, " ".html_safe], html.html_safe)
   end
   end
def view_helper(answer)
def view_helper(answer)
     html = self.text
     html = self.text
     html += answer.comments
     html += answer.comments
     html += '<BR/><BR/>'
     html += '<BR/><BR/>'
     html
     html
end
end

Revision as of 20:23, 28 October 2016

E1673. Refactor question type.rb

Reason for Refractor

Some codes are so duplicated and unreadability. It's difficult to make extensions and develop.

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
def view_completed_question(count, answer)
   if self.type == 'TextField' and self.break_before == true
     html = '' + count.to_s + ". " + self.txt + ""
     html += '    '
     html += answer.comments
     html += '

' if Question.exists?(answer.question_id + 1) && Question.find(answer.question_id + 1).break_before == true else html = view_helper(answer) end safe_join([" ".html_safe, " ".html_safe], html.html_safe) end def view_helper(answer) html = self.text html += answer.comments html += '

' html end