Class: Quby::Compiler::Entities::QuestionOption
- Inherits:
-
Object
- Object
- Quby::Compiler::Entities::QuestionOption
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/quby/compiler/entities/question_option.rb
Constant Summary collapse
- MARKDOWN_ATTRIBUTES =
%w(description).freeze
Instance Attribute Summary collapse
-
#context_free_description ⇒ Object
readonly
Returns the value of attribute context_free_description.
-
#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
for scale/radio/checbox questions, piece of of html that is rendered between the options.
-
#input_key ⇒ Object
readonly
Returns the value of attribute input_key.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#placeholder ⇒ Object
readonly
for select questions, option with no value and key is removed from answers if this one is selected.
-
#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
-
#initialize(key, question, options = {}) ⇒ QuestionOption
constructor
A new instance of QuestionOption.
- #inner_title? ⇒ Boolean
- #inner_title_as_json(options = {}) ⇒ Object
- #key_in_use?(k) ⇒ Boolean
- #option_as_json(options = {}) ⇒ Object
Constructor Details
#initialize(key, question, options = {}) ⇒ QuestionOption
Returns a new instance of QuestionOption.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/quby/compiler/entities/question_option.rb', line 29 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
#context_free_description ⇒ Object (readonly)
Returns the value of attribute context_free_description.
13 14 15 |
# File 'lib/quby/compiler/entities/question_option.rb', line 13 def context_free_description @context_free_description end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
13 14 15 |
# File 'lib/quby/compiler/entities/question_option.rb', line 13 def description @description end |
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden.
20 21 22 |
# File 'lib/quby/compiler/entities/question_option.rb', line 20 def hidden @hidden end |
#hides_questions ⇒ Object (readonly)
Returns the value of attribute hides_questions.
18 19 20 |
# File 'lib/quby/compiler/entities/question_option.rb', line 18 def hides_questions @hides_questions end |
#inner_title ⇒ Object (readonly)
for scale/radio/checbox questions, piece of of html that is rendered between the options
16 17 18 |
# File 'lib/quby/compiler/entities/question_option.rb', line 16 def inner_title @inner_title end |
#input_key ⇒ Object (readonly)
Returns the value of attribute input_key.
27 28 29 |
# File 'lib/quby/compiler/entities/question_option.rb', line 27 def input_key @input_key end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
11 12 13 |
# File 'lib/quby/compiler/entities/question_option.rb', line 11 def key @key end |
#placeholder ⇒ Object (readonly)
for select questions, option with no value and key is removed from answers if this one is selected.
23 24 25 |
# File 'lib/quby/compiler/entities/question_option.rb', line 23 def placeholder @placeholder end |
#question ⇒ Object (readonly)
Returns the value of attribute question.
25 26 27 |
# File 'lib/quby/compiler/entities/question_option.rb', line 25 def question @question end |
#questions ⇒ Object (readonly)
Returns the value of attribute questions.
14 15 16 |
# File 'lib/quby/compiler/entities/question_option.rb', line 14 def questions @questions end |
#shows_questions ⇒ Object (readonly)
Returns the value of attribute shows_questions.
19 20 21 |
# File 'lib/quby/compiler/entities/question_option.rb', line 19 def shows_questions @shows_questions end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
12 13 14 |
# File 'lib/quby/compiler/entities/question_option.rb', line 12 def value @value end |
#view_id ⇒ Object (readonly)
Returns the value of attribute view_id.
26 27 28 |
# File 'lib/quby/compiler/entities/question_option.rb', line 26 def view_id @view_id end |
Instance Method Details
#as_json(options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/quby/compiler/entities/question_option.rb', line 57 def as_json( = {}) if inner_title inner_title_as_json() elsif placeholder nil # placeholder attr on question. else option_as_json() end end |
#inner_title? ⇒ Boolean
47 48 49 |
# File 'lib/quby/compiler/entities/question_option.rb', line 47 def inner_title? inner_title.present? end |
#inner_title_as_json(options = {}) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/quby/compiler/entities/question_option.rb', line 67 def inner_title_as_json( = {}) { type: 'html', key: SecureRandom.uuid, html: Quby::Compiler::MarkdownParser.new(description).to_html } end |
#key_in_use?(k) ⇒ Boolean
51 52 53 54 55 |
# File 'lib/quby/compiler/entities/question_option.rb', line 51 def key_in_use?(k) return true if k == input_key @questions.each { |q| return true if q.key_in_use?(k) } false end |
#option_as_json(options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/quby/compiler/entities/question_option.rb', line 75 def option_as_json( = {}) { type: 'option', key: key, value: value, description: question.type == :select \ ? description : Quby::Compiler::MarkdownParser.new(description).to_html, questions: questions, hidesQuestions: hides_questions, showsQuestions: shows_questions, hidden: hidden, viewId: view_id } end |