Module: Quby::Questionnaires::DSL::Questions::Subquestions

Included in:
CheckboxQuestionBuilder, RadioQuestionBuilder
Defined in:
lib/quby/questionnaires/dsl/questions/base.rb

Instance Method Summary collapse

Instance Method Details

#buildObject



119
120
121
122
123
124
125
126
# File 'lib/quby/questionnaires/dsl/questions/base.rb', line 119

def build
  if @title_question
    @question.options.last.questions << @title_question
    @title_question = nil
  end

  super
end

#initialize(key, options = {}, &block) ⇒ Object



113
114
115
116
117
# File 'lib/quby/questionnaires/dsl/questions/base.rb', line 113

def initialize(key, options = {}, &block)
  super
  @default_question_options = options[:default_question_options] || {}
  @title_question = nil
end

#question(key, options = {}, &block) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/quby/questionnaires/dsl/questions/base.rb', line 143

def question(key, options = {}, &block)
  options = @default_question_options.merge(options)
                                     .merge(questionnaire: @questionnaire,
                                            parent: @question,
                                            parent_option_key: @question.options.last.key)

  check_question_keys_uniqueness key, options, @questionnaire

  question = QuestionBuilder.build(key, options, &block)

  @questionnaire.register_question(question)
  @question.options.last.questions << question
end

#title_question(key, options = {}, &block) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/quby/questionnaires/dsl/questions/base.rb', line 128

def title_question(key, options = {}, &block)
  options = @default_question_options.merge({depends_on: @question.key,
                                             questionnaire: @questionnaire,
                                             parent: @question,
                                             presentation: :next_to_title,
                                             allow_blank_titles: @question.allow_blank_titles}.merge(options))

  check_question_keys_uniqueness key, options, @questionnaire

  question = QuestionBuilder.build(key, options, &block)

  @questionnaire.register_question(question)
  @title_question = question
end