Class: ActiveRecordSurvey::Survey
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActiveRecordSurvey::Survey
- Defined in:
- lib/active_record_survey/survey.rb
Instance Method Summary collapse
- #as_map(*args) ⇒ Object
-
#build_first_question(question_node) ⇒ Object
Builds first question.
-
#edges ⇒ Object
All the connective edges.
- #root_node ⇒ Object
Instance Method Details
#as_map(*args) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/active_record_survey/survey.rb', line 42 def as_map(*args) = args. [:node_maps] ||= self.node_maps self.node_maps.select { |i| !i.parent && !i.marked_for_destruction? }.collect { |i| i.as_map() } end |
#build_first_question(question_node) ⇒ Object
Builds first question
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_record_survey/survey.rb', line 15 def build_first_question(question_node) if !question_node.class.ancestors.include?(::ActiveRecordSurvey::Node::Question) raise ArgumentError.new "must inherit from ::ActiveRecordSurvey::Node::Question" end question_node_maps = self.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.node_maps.build(:node => question_node, :survey => self) end end |
#edges ⇒ Object
All the connective edges
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/active_record_survey/survey.rb', line 30 def edges self.node_maps.includes(:node, parent:[ :node ]) .select { |i| !i.marked_for_destruction? }.select { |i| i.node && i.parent }.collect { |i| { :source => i.parent.node.id, :target => i.node.id, } }.uniq end |
#root_node ⇒ Object
10 11 12 |
# File 'lib/active_record_survey/survey.rb', line 10 def root_node self.node_maps.includes(:node).select { |i| i.depth === 0 }.first end |