Sha256: 32b3d2c4d2c1481e02e91d1a934e7f424c929fb331b2f56d839528beafc484ab

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Quby
  module Questionnaires
    module Entities
      module Questions
        class CheckboxQuestion < Question
          # checkbox option that checks all other options on check
          attr_accessor :check_all_option

          # checkbox option that unchecks all other options on check
          attr_accessor :uncheck_all_option

          # checkbox option that allows to select a maximum amount of checkboxes
          attr_accessor :maximum_checked_allowed

          # checkbox option that forces to select a minimum amount of checkboxes
          attr_accessor :minimum_checked_required

          def initialize(key, options = {})
            super

            @check_all_option         = options[:check_all_option]
            @uncheck_all_option       = options[:uncheck_all_option]
            @maximum_checked_allowed  = options[:maximum_checked_allowed]
            @minimum_checked_required = options[:minimum_checked_required]
          end

          def claimed_keys
            [key]
          end

          def answer_keys
            # Some options don't have a key (inner_title), they are stripped.
            options.map { |opt| opt.input_key }.compact
          end

          def as_json(options = {})
            super.merge(options: @options.as_json)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
quby-5.6.5 lib/quby/questionnaires/entities/questions/checkbox_question.rb
quby-5.6.3 lib/quby/questionnaires/entities/questions/checkbox_question.rb
quby-5.6.2 lib/quby/questionnaires/entities/questions/checkbox_question.rb