Class: Quby::Questionnaires::Entities::QuestionOption

Inherits:
Object
  • Object
show all
Defined in:
lib/quby/questionnaires/entities/question_option.rb

Constant Summary collapse

MARKDOWN_ATTRIBUTES =
%w(description).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, question, options = {}) ⇒ QuestionOption

Returns a new instance of QuestionOption.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/quby/questionnaires/entities/question_option.rb', line 24

def initialize(key, question, options = {})
  @key         = key
  @question    = question
  @value       = options[:value]
  @description = options[:description]
  @context_free_description = options[:context_free_description]
  @questions   = []
  @inner_title = options[:inner_title]
  @hides_questions = options[:hides_questions] || []
  @shows_questions = options[:shows_questions] || []
  @hidden = options[:hidden] || false
  @placeholder = options[: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

#descriptionObject (readonly)

Returns the value of attribute description.



13
14
15
# File 'lib/quby/questionnaires/entities/question_option.rb', line 13

def description
  @description
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



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

def hidden
  @hidden
end

#hides_questionsObject (readonly)

Returns the value of attribute hides_questions.



16
17
18
# File 'lib/quby/questionnaires/entities/question_option.rb', line 16

def hides_questions
  @hides_questions
end

#inner_titleObject (readonly)

Returns the value of attribute inner_title.



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

def inner_title
  @inner_title
end

#input_keyObject (readonly)

Returns the value of attribute input_key.



22
23
24
# File 'lib/quby/questionnaires/entities/question_option.rb', line 22

def input_key
  @input_key
end

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/quby/questionnaires/entities/question_option.rb', line 11

def key
  @key
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



19
20
21
# File 'lib/quby/questionnaires/entities/question_option.rb', line 19

def placeholder
  @placeholder
end

#questionObject (readonly)

Returns the value of attribute question.



20
21
22
# File 'lib/quby/questionnaires/entities/question_option.rb', line 20

def question
  @question
end

#questionsObject (readonly)

Returns the value of attribute questions.



14
15
16
# File 'lib/quby/questionnaires/entities/question_option.rb', line 14

def questions
  @questions
end

#shows_questionsObject (readonly)

Returns the value of attribute shows_questions.



17
18
19
# File 'lib/quby/questionnaires/entities/question_option.rb', line 17

def shows_questions
  @shows_questions
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

#view_idObject (readonly)

Returns the value of attribute view_id.



21
22
23
# File 'lib/quby/questionnaires/entities/question_option.rb', line 21

def view_id
  @view_id
end

Instance Method Details

#as_json(options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/quby/questionnaires/entities/question_option.rb', line 56

def as_json(options = {})
  {
    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_descriptionObject



52
53
54
# File 'lib/quby/questionnaires/entities/question_option.rb', line 52

def context_free_description
  @context_free_description || @description
end

#inner_title?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/quby/questionnaires/entities/question_option.rb', line 42

def inner_title?
  inner_title.present?
end

#key_in_use?(k) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/quby/questionnaires/entities/question_option.rb', line 46

def key_in_use?(k)
  return true if k == input_key
  @questions.each { |q| return true if q.key_in_use?(k) }
  false
end