Class: Quby::Questionnaires::Entities::Questions::CheckboxQuestion

Inherits:
Quby::Questionnaires::Entities::Question show all
Defined in:
lib/quby/questionnaires/entities/questions/checkbox_question.rb

Constant Summary

Constants inherited from Quby::Questionnaires::Entities::Question

Quby::Questionnaires::Entities::Question::MARKDOWN_ATTRIBUTES

Instance Attribute Summary collapse

Attributes inherited from Quby::Questionnaires::Entities::Question

#allow_blank_titles, #allow_duplicate_option_values, #as, #autocomplete, #col_span, #cols, #context_free_title, #default_invisible, #default_position, #dependencies, #depends_on, #description, #deselectable, #disallow_bulk, #display_modes, #extra_data, #group_maximum_answered, #group_minimum_answered, #hidden, #input_data, #key, #labels, #lines, #maximum, #minimum, #options, #parent, #parent_option_key, #question_group, #questionnaire, #row_span, #sbg_key, #score_header, #sets_textvar, #show_values, #size, #table, #title, #type, #unit, #validations

Attributes inherited from Item

#presentation, #raw_content, #switch_cycle

Instance Method Summary collapse

Methods inherited from Quby::Questionnaires::Entities::Question

#codebook_key, #codebook_output_range, #codebook_output_type, #hidden?, #html_id, #input_keys, #key_in_use?, #set_depends_on, #show_values_in_mode?, #subquestion?, #subquestions, #view_selector

Constructor Details

#initialize(key, options = {}) ⇒ CheckboxQuestion

Returns a new instance of CheckboxQuestion.



20
21
22
23
24
25
26
27
# File 'lib/quby/questionnaires/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]
end

Instance Attribute Details

#check_all_optionObject

checkbox option that checks all other options on check



9
10
11
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 9

def check_all_option
  @check_all_option
end

#maximum_checked_allowedObject

checkbox option that allows to select a maximum amount of checkboxes



15
16
17
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 15

def maximum_checked_allowed
  @maximum_checked_allowed
end

#minimum_checked_requiredObject

checkbox option that forces to select a minimum amount of checkboxes



18
19
20
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 18

def minimum_checked_required
  @minimum_checked_required
end

#uncheck_all_optionObject

checkbox option that unchecks all other options on check



12
13
14
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 12

def uncheck_all_option
  @uncheck_all_option
end

Instance Method Details

#answer_keysObject



40
41
42
43
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 40

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 = {}) ⇒ Object



45
46
47
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 45

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

#claimed_keysObject



36
37
38
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 36

def claimed_keys
  [key]
end

#to_codebook(questionnaire, opts = {}) ⇒ Object



49
50
51
52
53
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 49

def to_codebook(questionnaire, opts = {})
  options.map do |option|
    option.to_codebook(questionnaire, opts)
  end.compact.join("\n\n")
end

#variable_descriptionsObject



29
30
31
32
33
34
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 29

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