Class: GuidedPath::QuestionMultipleChoiceNode

Inherits:
Node
  • Object
show all
Defined in:
lib/guided_path/question_multiple_choice_node.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#label, #next_node

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ QuestionMultipleChoiceNode

Returns a new instance of QuestionMultipleChoiceNode.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
# File 'lib/guided_path/question_multiple_choice_node.rb', line 9

def initialize(args = {})
  super
  args = args.symbolize_keys
  
  @answers = args[:answers] 
  raise(ArgumentError, "Must specify answers in an Hash") unless args[:answers] && args[:answers].kind_of?(Hash)
  @text = args[:text]
end

Instance Attribute Details

#answersObject (readonly)

Returns the value of attribute answers.



7
8
9
# File 'lib/guided_path/question_multiple_choice_node.rb', line 7

def answers
  @answers
end

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'lib/guided_path/question_multiple_choice_node.rb', line 7

def text
  @text
end

Instance Method Details

#to_hashObject



19
20
21
22
23
24
25
# File 'lib/guided_path/question_multiple_choice_node.rb', line 19

def to_hash
  output = super
  output[:type] = 'question_multiple_choice'
  output[:answers] = Hash[@answers.collect { |answer,node| [answer, node.label] }]
  output[:text] = @text
  return output
end