Class: Quby::Compiler::DSL::TableBuilder

Inherits:
Object
  • Object
show all
Includes:
CallsCustomMethods, Helpers
Defined in:
lib/quby/compiler/dsl/table_builder.rb

Instance Attribute Summary

Attributes included from CallsCustomMethods

#custom_methods

Instance Method Summary collapse

Methods included from Helpers

#check_question_keys_uniqueness, #image_alt, #image_tag, #video_tag

Methods included from CallsCustomMethods

#method_missing, #respond_to_missing?

Constructor Details

#initialize(panel, default_question_options: {}, **options) ⇒ TableBuilder

Returns a new instance of TableBuilder.



12
13
14
15
16
17
# File 'lib/quby/compiler/dsl/table_builder.rb', line 12

def initialize(panel, default_question_options: {}, **options)
  @panel = panel
  @table = Entities::Table.new(options)
  @default_question_options = default_question_options
  @panel.items << @table
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Quby::Compiler::DSL::CallsCustomMethods

Instance Method Details

#description(value) ⇒ Object



23
24
25
# File 'lib/quby/compiler/dsl/table_builder.rb', line 23

def description(value)
  @table.description = value
end

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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/quby/compiler/dsl/table_builder.rb', line 31

def question(key, **options, &block)
  options = @default_question_options.merge(options)
                                     .merge(table: @table,
                                            questionnaire: @panel.questionnaire)

  check_question_keys_uniqueness key, options, @panel.questionnaire
  fail "You can't create a slider in a table at the moment" if options[:as] == :slider

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

  @panel.questionnaire.register_question(question)
  @table.items << question
  @panel.items << question
end

#text(value, **options) ⇒ Object



27
28
29
# File 'lib/quby/compiler/dsl/table_builder.rb', line 27

def text(value, **options)
  @table.items << Entities::Text.new(value.to_s, options)
end

#title(value) ⇒ Object



19
20
21
# File 'lib/quby/compiler/dsl/table_builder.rb', line 19

def title(value)
  @table.title = value
end