class Quby::Compiler::Entities::Questions::CheckboxQuestion

Attributes

check_all_option[RW]

checkbox option that checks all other options on check

maximum_checked_allowed[RW]

checkbox option that allows to select a maximum amount of checkboxes

minimum_checked_required[RW]

checkbox option that forces to select a minimum amount of checkboxes

uncheck_all_option[RW]

checkbox option that unchecks all other options on check

Public Class Methods

new(key, options = {}) click to toggle source
Calls superclass method Quby::Compiler::Entities::Question::new
# File lib/quby/compiler/entities/questions/checkbox_question.rb, line 20
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]

  if @check_all_option
    @validations << {type: :not_all_checked,
                     check_all_key: @check_all_option,
                     explanation: options[:error_explanation]}
  end

  if @uncheck_all_option
    @validations << {type: :too_many_checked,
                     uncheck_all_key: @uncheck_all_option,
                     explanation: options[:error_explanation]}
  end

  if @maximum_checked_allowed
    @validations << {type: :maximum_checked_allowed,
                     maximum_checked_value: @maximum_checked_allowed,
                     explanation: options[:error_explanation]}
  end

  if @minimum_checked_required
    @validations << {type: :minimum_checked_required,
                     minimum_checked_value: @minimum_checked_required,
                     explanation: options[:error_explanation]}
  end
end

Public Instance Methods

answer_keys() click to toggle source
# File lib/quby/compiler/entities/questions/checkbox_question.rb, line 64
def answer_keys
  # Some options don't have a key (inner_title), they are stripped.
  options.map { |opt| opt.input_key }.compact
end
as_json(options = {}) click to toggle source
# File lib/quby/compiler/entities/questions/checkbox_question.rb, line 69
def as_json(options = {})
  super.merge(options: @options.as_json)
end
claimed_keys() click to toggle source
# File lib/quby/compiler/entities/questions/checkbox_question.rb, line 60
def claimed_keys
  [key]
end
to_codebook(questionnaire, opts = {}) click to toggle source
# File lib/quby/compiler/entities/questions/checkbox_question.rb, line 73
def to_codebook(questionnaire, opts = {})
  options.map do |option|
    option.to_codebook(questionnaire, opts)
  end.compact.join("\n\n")
end
variable_descriptions() click to toggle source
# File lib/quby/compiler/entities/questions/checkbox_question.rb, line 53
def variable_descriptions
  options.each_with_object(key => context_free_title) do |option, hash|
    next if option.input_key.blank?
    hash[option.input_key] = "#{context_free_title} - #{option.description}"
  end.with_indifferent_access
end