Sha256: 155d2639e34491e7b56a04f1637a8dc56a33416463be1a2a9a28a13a63d000cd

Contents?: true

Size: 1.35 KB

Versions: 32

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

require 'quby/compiler/entities'

module Quby
  module Compiler
    module DSL
      class TableBuilder
        prepend CallsCustomMethods
        include Helpers

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

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

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

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

        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
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
quby-compiler-0.5.9 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.5.8 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.5.7 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.5.6 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.5.5 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.5.4 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.5.3 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.5.2 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.5.1 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.5.0 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.4.16 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.4.15 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.4.14 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.4.13 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.4.12 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.4.11 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.4.10 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.4.9 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.4.8 lib/quby/compiler/dsl/table_builder.rb
quby-compiler-0.4.7 lib/quby/compiler/dsl/table_builder.rb