Class: Effective::PollQuestion

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/poll_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



117
118
119
# File 'app/models/effective/poll_question.rb', line 117

def category_partial
  category.to_s.parameterize.underscore
end

#poll_question_option?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'app/models/effective/poll_question.rb', line 113

def poll_question_option?
  WITH_OPTIONS_CATEGORIES.include?(category)
end

#show_if_attributeObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/effective/poll_question.rb', line 91

def show_if_attribute
  return :poll_question_option_ids if poll_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



105
106
107
# File 'app/models/effective/poll_question.rb', line 105

def show_if_value
  poll_question.try(:poll_question_option?) ? poll_question_option_id : follow_up_value
end

#show_if_value_to_sObject



109
110
111
# File 'app/models/effective/poll_question.rb', line 109

def show_if_value_to_s
  (poll_question.try(:poll_question_option?) ? poll_question_option : follow_up_value).to_s
end

#to_sObject



87
88
89
# File 'app/models/effective/poll_question.rb', line 87

def to_s
  title.presence || model_name.human
end