Class: Quby::Questionnaires::Entities::Questions::CheckboxQuestion
- Inherits:
-
Quby::Questionnaires::Entities::Question
- Object
- Item
- Quby::Questionnaires::Entities::Question
- Quby::Questionnaires::Entities::Questions::CheckboxQuestion
- 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
-
#check_all_option ⇒ Object
checkbox option that checks all other options on check.
-
#maximum_checked_allowed ⇒ Object
checkbox option that allows to select a maximum amount of checkboxes.
-
#minimum_checked_required ⇒ Object
checkbox option that forces to select a minimum amount of checkboxes.
-
#uncheck_all_option ⇒ Object
checkbox option that unchecks all other options on check.
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
- #answer_keys ⇒ Object
- #as_json(options = {}) ⇒ Object
- #claimed_keys ⇒ Object
-
#initialize(key, options = {}) ⇒ CheckboxQuestion
constructor
A new instance of CheckboxQuestion.
- #to_codebook(questionnaire, opts = {}) ⇒ Object
- #variable_descriptions ⇒ Object
Methods inherited from Quby::Questionnaires::Entities::Question
#codebook_key, #codebook_output_range, #codebook_output_type, #expand_depends_on_input_keys, #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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 20 def initialize(key, = {}) super @check_all_option = [:check_all_option] @uncheck_all_option = [:uncheck_all_option] @maximum_checked_allowed = [:maximum_checked_allowed] @minimum_checked_required = [:minimum_checked_required] if @check_all_option @validations << {type: :not_all_checked, check_all_key: @check_all_option, explanation: [:error_explanation]} end if @uncheck_all_option @validations << {type: :too_many_checked, uncheck_all_key: @uncheck_all_option, explanation: [:error_explanation]} end if @maximum_checked_allowed @validations << {type: :maximum_checked_allowed, maximum_checked_value: @maximum_checked_allowed, explanation: [:error_explanation]} end if @minimum_checked_required @validations << {type: :minimum_checked_required, minimum_checked_value: @minimum_checked_required, explanation: [:error_explanation]} end end |
Instance Attribute Details
#check_all_option ⇒ Object
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_allowed ⇒ Object
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_required ⇒ Object
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_option ⇒ Object
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_keys ⇒ Object
64 65 66 67 |
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 64 def answer_keys # Some options don't have a key (inner_title), they are stripped. .map { |opt| opt.input_key }.compact end |
#as_json(options = {}) ⇒ Object
69 70 71 |
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 69 def as_json( = {}) super.merge(options: @options.as_json) end |
#claimed_keys ⇒ Object
60 61 62 |
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 60 def claimed_keys [key] end |
#to_codebook(questionnaire, opts = {}) ⇒ Object
73 74 75 76 77 |
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 73 def to_codebook(questionnaire, opts = {}) .map do |option| option.to_codebook(questionnaire, opts) end.compact.join("\n\n") end |
#variable_descriptions ⇒ Object
53 54 55 56 57 58 |
# File 'lib/quby/questionnaires/entities/questions/checkbox_question.rb', line 53 def variable_descriptions .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 |