Class: Quby::Compiler::DSL::Questions::SelectQuestionBuilder
- Includes:
- CompareVisibilityRule
- Defined in:
- lib/quby/compiler/dsl/questions/select_question_builder.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(key, **options, &block) ⇒ SelectQuestionBuilder
constructor
A new instance of SelectQuestionBuilder.
- #optgroup(key, label:, &block) ⇒ Object
- #option(key, options = {}, &block) ⇒ Object
Methods included from CompareVisibilityRule
Methods inherited from Base
#build, #context_description, #context_free_title, #default_position, #depends_on, #description, #hidden, #presentation, #title, #validates_presence_of_answer
Methods inherited from Base
Methods included from Helpers
#check_key_uniqueness, #check_question_keys_uniqueness, #image_alt, #image_tag, #video_tag
Constructor Details
#initialize(key, **options, &block) ⇒ SelectQuestionBuilder
Returns a new instance of SelectQuestionBuilder.
10 11 12 13 14 |
# File 'lib/quby/compiler/dsl/questions/select_question_builder.rb', line 10 def initialize(key, **, &block) super @question = Entities::Questions::SelectQuestion.new(key, ) @current_optgroup = nil end |
Instance Method Details
#optgroup(key, label:, &block) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/quby/compiler/dsl/questions/select_question_builder.rb', line 16 def optgroup(key, label: , &block) raise "Cannot nest optgroups" if @current_optgroup @question. << @current_optgroup = Entities::QuestionOptgroup.new(key, label:) instance_eval(&block) @current_optgroup = nil end |
#option(key, options = {}, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/quby/compiler/dsl/questions/select_question_builder.rb', line 23 def option(key, = {}, &block) question_option = Entities::QuestionOption.new(key, @question, ) if @questionnaire.key_in_use?(question_option.input_key) || @question.key_in_use?(question_option.input_key) fail "#{questionnaire.key}:#{@question.key}:#{question_option.key}: " \ "A question or option with input key #{question_option.input_key} is already defined." end if @current_optgroup @current_optgroup. << question_option else @question. << question_option end end |