Skip to content

Instantly share code, notes, and snippets.

@namtx
Created February 12, 2018 04:17
Show Gist options
  • Save namtx/89adb5f3b8bed95abd10ca6fa373bcb1 to your computer and use it in GitHub Desktop.
Save namtx/89adb5f3b8bed95abd10ca6fa373bcb1 to your computer and use it in GitHub Desktop.
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