Created
May 20, 2013 15:28
-
-
Save knewter/5612952 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def valid_score_method | |
if score_as_multi? | |
unless valid_scoring_for_multi | |
self.errors[:base] << "Score Method must be None, Sum or Max for Checkbox or Select-multiple tags" | |
return false | |
end | |
elsif score_as_text? | |
unless valid_scoring_for_text? | |
self.errors[:base] << "Score Method must be None, TextCompletion or TextNumeric for Text or Textarea tags" | |
return false | |
end | |
else | |
unless valid_scoring_for_generic? | |
self.errors[:base] << "Score Method #{score_method} invalid for tag #{answer_tag}" | |
return false | |
end | |
end | |
end | |
private | |
def score_as_multi? | |
answer_type_in?(['checkbox', 'select-multiple']) | |
end | |
def score_as_text? | |
answer_type_in?(['text', 'textarea']) | |
end | |
def answer_type_in?(valid_types) | |
valid_types.include?(answer_tag.downcase) | |
end | |
def valid_scoring_for_multi? | |
score_method_in?(['sum', 'max', 'none']) | |
end | |
def valid_scoring_for_text? | |
score_method_in?('textcontains', 'textnumeric', 'none') | |
end | |
def valid_scoring_for_generic? | |
score_method_in?('value', 'none') | |
end | |
def score_method_in?(valid_score_methods) | |
valid_score_methods.include?(score_method.downcase) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment