Sha256: 5de4fb7c9f195c4ac16c664727fde0da8bc3201c907fab999db3a45607d2e235

Contents?: true

Size: 940 Bytes

Versions: 3

Compression:

Stored size: 940 Bytes

Contents

module ActiveRecordSurvey
	class Answer
		module Chained
			# Chain nodes are different - they must find the final answer node added and add to it
			def build_answer(question_node)
				self.survey = question_node.survey

				question_node_maps = self.survey.node_maps.select { |i| i.node == question_node && !i.marked_for_destruction? }

				# No node_maps exist yet from this question
				if question_node_maps.length === 0
					# Build our first node-map
					question_node_maps << self.survey.node_maps.build(:node => question_node, :survey => self.survey)
				end

				last_answer_in_chain = (question_node.answers.last || question_node)

				# Each instance of this question needs the answer hung from it
				self.survey.node_maps.select { |i|
					i.node == last_answer_in_chain
				}.each { |node_map|
					node_map.children << self.survey.node_maps.build(:node => self, :survey => self.survey)
				}

				true
			end
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_record_survey-0.1.28 lib/active_record_survey/node/answer/chained.rb
active_record_survey-0.1.27 lib/active_record_survey/node/answer/chained.rb
active_record_survey-0.1.26 lib/active_record_survey/node/answer/chained.rb