Created
February 12, 2018 04:17
-
-
Save namtx/89adb5f3b8bed95abd10ca6fa373bcb1 to your computer and use it in GitHub Desktop.
This file contains 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
class Quesion < ApplicationRecord | |
SUBMITITABLE_TYPES = %w(Open MultipleChoice Scale).freeze | |
validates :maximum, presence: true, if: :scale? | |
validates :minimum, presence: true, if: :scale? | |
validates :question_type, presence: true, inclusion: SUBMITITABLE_TYPES | |
validates :title, presence: true | |
def summary | |
case question_type | |
when "MultipleChoice" | |
summarize_multiple_choice_answers | |
when "Open" | |
summarize_open_answers | |
when "Scale" | |
summarize_scale_answers | |
end | |
end | |
def steps | |
(minimum..maximum).to_a | |
end | |
private | |
def scale? | |
question_type == "Scale" | |
end | |
def summarize_multiple_choice_answers | |
"Multiple Choice Answer" | |
end | |
def summarize_open_answers | |
"Open Answer" | |
end | |
def summarize_scale_answers | |
"Scale Answer" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment