Class: Effective::Question
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::Question
- 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 'Decimal', # Decimal Field 'Email', # Email Field 'Number', # Numeric Field 'Percentage', # Percentage Field 'Price', # Price 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
- #answer ⇒ Object
- #answer_options ⇒ Object
- #answer_to_s ⇒ Object
- #category_partial ⇒ Object
- #question_answer ⇒ Object
- #question_option? ⇒ Boolean
- #show_if_attribute ⇒ Object
- #show_if_value ⇒ Object
- #show_if_value_to_s ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#answer ⇒ Object
144 145 146 147 |
# File 'app/models/effective/question.rb', line 144 def answer return unless scored? question_option? ? : question_answer.try(:answer) end |
#answer_options ⇒ Object
176 177 178 |
# File 'app/models/effective/question.rb', line 176 def .reject(&:marked_for_destruction?).select(&:answer?) end |
#answer_to_s ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/models/effective/question.rb', line 149 def answer_to_s return '' unless scored? case category when 'Choose one' then "One of: #{.join(', ')}" when 'Select all that apply' then "All of: #{.join(', ')}" when 'Select up to 1' then "One of: #{.join(', ')}" when 'Select up to 2' then "Two of: #{.join(', ')}" when 'Select up to 3' then "Three of: #{.join(', ')}" when 'Select up to 4' then "Four of: #{.join(', ')}" when 'Select up to 5' then "Five of: #{.join(', ')}" else question_answer.try(:to_s) end end |
#category_partial ⇒ Object
180 181 182 |
# File 'app/models/effective/question.rb', line 180 def category_partial category.to_s.parameterize.underscore end |
#question_answer ⇒ Object
184 185 186 |
# File 'app/models/effective/question.rb', line 184 def question_answer question_answers.first || question_answers.build() end |
#question_option? ⇒ Boolean
172 173 174 |
# File 'app/models/effective/question.rb', line 172 def question_option? WITH_OPTIONS_CATEGORIES.include?(category) end |
#show_if_attribute ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/models/effective/question.rb', line 127 def show_if_attribute return :question_option_ids if question_option? case category when 'Date' then :date when 'Decimal' then :decimal when 'Email' then :email when 'Number' then :number when 'Percentage' then :percentage when 'Price' then :price when 'Long Answer' then :long_answer when 'Short Answer' then :short_answer when 'Upload File' then :upload_file else :unknown end end |
#show_if_value ⇒ Object
164 165 166 |
# File 'app/models/effective/question.rb', line 164 def show_if_value question.try(:question_option?) ? question_option_id : follow_up_value end |
#show_if_value_to_s ⇒ Object
168 169 170 |
# File 'app/models/effective/question.rb', line 168 def show_if_value_to_s (question.try(:question_option?) ? question_option : follow_up_value).to_s end |
#to_s ⇒ Object
123 124 125 |
# File 'app/models/effective/question.rb', line 123 def to_s title.presence || model_name.human end |