Class: Effective::Question

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/question.rb

Constant Summary collapse

CATEGORIES =
[
  'Choose one',   # Radios
  'Select all that apply', # Checks
  'Select up to 1',
  'Select up to 2',
  'Select up to 3',
  'Select up to 4',
  'Select up to 5',
  'Date',         # Date Field
  'Email',        # Email Field
  'Number',       # Numeric Field
  'Long Answer',  # Text Area
  'Short Answer', # Text Field
  'Upload File'   # File field
]
WITH_OPTIONS_CATEGORIES =
[
  'Choose one',   # Radios
  'Select all that apply', # Checks
  'Select up to 1',
  'Select up to 2',
  'Select up to 3',
  'Select up to 4',
  'Select up to 5'
]
UNSUPPORTED_FOLLOW_UP_QUESTION_CATEGORIES =
['Upload File']

Instance Method Summary collapse

Instance Method Details

#category_partialObject



119
120
121
# File 'app/models/effective/question.rb', line 119

def category_partial
  category.to_s.parameterize.underscore
end

#question_option?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'app/models/effective/question.rb', line 115

def question_option?
  WITH_OPTIONS_CATEGORIES.include?(category)
end

#show_if_attributeObject



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/effective/question.rb', line 93

def show_if_attribute
  return :question_option_ids if question_option?

  case category
  when 'Date' then :date
  when 'Email' then :email
  when 'Number' then :number
  when 'Long Answer' then :long_answer
  when 'Short Answer' then :short_answer
  when 'Upload File' then :upload_file
  else :unknown
  end
end

#show_if_valueObject



107
108
109
# File 'app/models/effective/question.rb', line 107

def show_if_value
  question.try(:question_option?) ? question_option_id : follow_up_value
end

#show_if_value_to_sObject



111
112
113
# File 'app/models/effective/question.rb', line 111

def show_if_value_to_s
  (question.try(:question_option?) ? question_option : follow_up_value).to_s
end

#to_sObject



89
90
91
# File 'app/models/effective/question.rb', line 89

def to_s
  title.presence || model_name.human
end