Class: SurveyGizmo::API::Question

Inherits:
Object
  • Object
show all
Includes:
MultilingualTitle, Resource
Defined in:
lib/survey_gizmo/api/question.rb

Instance Method Summary collapse

Methods included from MultilingualTitle

#title=

Methods included from Resource

descendants, #destroy, #inspect, #reload, #save

Instance Method Details

#optionsObject



33
34
35
36
37
38
# File 'lib/survey_gizmo/api/question.rb', line 33

def options
  return parent_question.options.dup.each { |o| o.question_id = id } if parent_question

  @options ||= Option.all(children_params.merge(all_pages: true)).to_a
  @options.each { |o| o.attributes = children_params }
end

#parent_questionObject



40
41
42
43
# File 'lib/survey_gizmo/api/question.rb', line 40

def parent_question
  return nil unless parent_question_id
  @parent_question ||= Question.first(survey_id: survey_id, id: parent_question_id)
end

#sub_question_skusObject



45
46
47
48
49
50
# File 'lib/survey_gizmo/api/question.rb', line 45

def sub_question_skus
  # As of 2015-12-23, the sub_question_skus attribute can either contain an array of integers if no shortname (alias)
  # was set for any question, or an array of [String, Integer] with the String corresponding to the subquestion
  # shortname and the integer corresponding to the subquestion id if at least one shortname was set.
  @sub_question_skus.map { |sku| sku.is_a?(Array) ? sku[1] : sku }
end

#sub_questionsObject



52
53
54
55
56
57
58
59
# File 'lib/survey_gizmo/api/question.rb', line 52

def sub_questions
  @sub_questions ||= sub_question_skus.map do |sku|
    SurveyGizmo.configuration.logger.debug("Have to do individual load of sub question #{sku}...")
    subquestion = Question.first(survey_id: survey_id, id: sku)
    subquestion.parent_question_id = id
    subquestion
  end
end

#surveyObject



29
30
31
# File 'lib/survey_gizmo/api/question.rb', line 29

def survey
  @survey ||= Survey.first(id: survey_id)
end