Class: Quby::Questionnaires::Entities::QuestionOption
- Inherits:
-
Object
- Object
- Quby::Questionnaires::Entities::QuestionOption
- Defined in:
- lib/quby/questionnaires/entities/question_option.rb
Constant Summary collapse
- MARKDOWN_ATTRIBUTES =
%w(description).freeze
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#hidden ⇒ Object
readonly
Returns the value of attribute hidden.
-
#hides_questions ⇒ Object
readonly
Returns the value of attribute hides_questions.
-
#inner_title ⇒ Object
readonly
Returns the value of attribute inner_title.
-
#input_key ⇒ Object
readonly
Returns the value of attribute input_key.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#placeholder ⇒ Object
readonly
Returns the value of attribute placeholder.
-
#question ⇒ Object
readonly
Returns the value of attribute question.
-
#questions ⇒ Object
readonly
Returns the value of attribute questions.
-
#shows_questions ⇒ Object
readonly
Returns the value of attribute shows_questions.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#view_id ⇒ Object
readonly
Returns the value of attribute view_id.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #context_free_description ⇒ Object
-
#initialize(key, question, options = {}) ⇒ QuestionOption
constructor
A new instance of QuestionOption.
- #inner_title? ⇒ Boolean
- #key_in_use?(k) ⇒ Boolean
- #to_codebook(questionnaire, opts) ⇒ Object
Constructor Details
#initialize(key, question, options = {}) ⇒ QuestionOption
Returns a new instance of QuestionOption.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 22 def initialize(key, question, = {}) @key = key @question = question @value = [:value] @description = [:description] @context_free_description = [:context_free_description] @questions = [] @inner_title = [:inner_title] @hides_questions = [:hides_questions] || [] @shows_questions = [:shows_questions] || [] @hidden = [:hidden] || false @placeholder = [:placeholder] || false question.extra_data[:placeholder] = key if @placeholder @input_key = (question.type == :check_box ? @key : "#{question.key}_#{key}".to_sym) @view_id = "answer_#{input_key}" end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
11 12 13 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 11 def description @description end |
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden.
16 17 18 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 16 def hidden @hidden end |
#hides_questions ⇒ Object (readonly)
Returns the value of attribute hides_questions.
14 15 16 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 14 def hides_questions @hides_questions end |
#inner_title ⇒ Object (readonly)
Returns the value of attribute inner_title.
13 14 15 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 13 def inner_title @inner_title end |
#input_key ⇒ Object (readonly)
Returns the value of attribute input_key.
20 21 22 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 20 def input_key @input_key end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 9 def key @key end |
#placeholder ⇒ Object (readonly)
Returns the value of attribute placeholder.
17 18 19 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 17 def placeholder @placeholder end |
#question ⇒ Object (readonly)
Returns the value of attribute question.
18 19 20 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 18 def question @question end |
#questions ⇒ Object (readonly)
Returns the value of attribute questions.
12 13 14 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 12 def questions @questions end |
#shows_questions ⇒ Object (readonly)
Returns the value of attribute shows_questions.
15 16 17 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 15 def shows_questions @shows_questions end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 10 def value @value end |
#view_id ⇒ Object (readonly)
Returns the value of attribute view_id.
19 20 21 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 19 def view_id @view_id end |
Instance Method Details
#as_json(options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 54 def as_json( = {}) { key: key, value: value, description: Quby::MarkdownParser.new(description).to_html, context_free_description: Quby::MarkdownParser.new(context_free_description).to_html, questions: questions, innerTitle: inner_title, hidesQuestions: hides_questions, showsQuestions: shows_questions, hidden: hidden, placeholder: placeholder, viewId: view_id } end |
#context_free_description ⇒ Object
50 51 52 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 50 def context_free_description @context_free_description || @description end |
#inner_title? ⇒ Boolean
40 41 42 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 40 def inner_title? inner_title.present? end |
#key_in_use?(k) ⇒ Boolean
44 45 46 47 48 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 44 def key_in_use?(k) return true if k == input_key @questions.each { |q| return true if q.key_in_use?(k) } false end |
#to_codebook(questionnaire, opts) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/quby/questionnaires/entities/question_option.rb', line 70 def to_codebook(questionnaire, opts) return nil if inner_title output = [] if question.type == :check_box option_key = question.codebook_key(key, questionnaire, opts) output << "#{option_key} #{question.codebook_output_type}#{' deprecated' if hidden || question.hidden }" output << "\"#{question.title} -- #{description}\"" unless question.title.blank? and description.blank? output << "1\tChecked" output << "0\tUnchecked" output << "empty\tUnchecked" else output << "#{value || key}\t\"#{description}\"#{' deprecated' if hidden}" end questions.each do |subquestion| output << "\t#{subquestion.to_codebook(questionnaire, opts).gsub("\n", "\n\t")}" end output.join("\n") end |