Module: Quby::Compiler::DSL::Questions::Subquestions

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

Instance Method Summary collapse

Instance Method Details

#initialize(key, **options, &block) ⇒ Object



111
112
113
114
# File 'lib/quby/compiler/dsl/questions/base.rb', line 111

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

#question(key, **options, &block) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/quby/compiler/dsl/questions/base.rb', line 131

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



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/quby/compiler/dsl/questions/base.rb', line 116

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)
  @question.title_question = question
end