Class: Quby::Compiler::DSL::InfoBlockBuilder
- Defined in:
- lib/quby/compiler/dsl/info_block_builder.rb
Instance Attribute Summary collapse
-
#default_question_options ⇒ Object
readonly
Returns the value of attribute default_question_options.
-
#info_block ⇒ Object
readonly
Returns the value of attribute info_block.
Instance Method Summary collapse
- #html(value, key: fallback_key) ⇒ Object
- #info_html(value) ⇒ Object
-
#initialize(key, panel:, default_question_options:, custom_methods:, **options) ⇒ InfoBlockBuilder
constructor
A new instance of InfoBlockBuilder.
- #method_missing(method_sym, *args, **kwargs, &block) ⇒ Object
- #question(key, **options, &block) ⇒ Object
- #text(key:, html: nil, md: nil, **options) ⇒ Object
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, panel:, default_question_options:, custom_methods:, **options) ⇒ InfoBlockBuilder
Returns a new instance of InfoBlockBuilder.
14 15 16 17 18 19 20 21 |
# File 'lib/quby/compiler/dsl/info_block_builder.rb', line 14 def initialize(key, panel:, default_question_options:, custom_methods:, **) @info_block = Entities::InfoBlock.new(key: , panel:, **) @default_question_options = @custom_methods = custom_methods check_key_uniqueness(key, questionnaire:) questionnaire.fields.info_block_keys << key panel.items << @info_block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *args, **kwargs, &block) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/quby/compiler/dsl/info_block_builder.rb', line 47 def method_missing(method_sym, *args, **kwargs, &block) if @custom_methods.key? method_sym instance_exec(*args, **kwargs, &@custom_methods[method_sym]) else super end end |
Instance Attribute Details
#default_question_options ⇒ Object (readonly)
Returns the value of attribute default_question_options.
9 10 11 |
# File 'lib/quby/compiler/dsl/info_block_builder.rb', line 9 def @default_question_options end |
#info_block ⇒ Object (readonly)
Returns the value of attribute info_block.
9 10 11 |
# File 'lib/quby/compiler/dsl/info_block_builder.rb', line 9 def info_block @info_block end |
Instance Method Details
#html(value, key: fallback_key) ⇒ Object
28 29 30 |
# File 'lib/quby/compiler/dsl/info_block_builder.rb', line 28 def html(value, key: fallback_key) info_block.items << Entities::Text.new('', html_content: value.to_s, key:) end |
#info_html(value) ⇒ Object
23 24 25 26 |
# File 'lib/quby/compiler/dsl/info_block_builder.rb', line 23 def info_html(value) raise "Can only add one info_html item per info_block" if info_block.html.present? info_block.html = value end |
#question(key, **options, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/quby/compiler/dsl/info_block_builder.rb', line 36 def question(key, **, &block) = .merge().merge(questionnaire:) check_question_keys_uniqueness key, , questionnaire question = QuestionBuilder.build(key, **, &block) questionnaire.register_question(question) info_block.items << question end |