Module: Dagraph::NodeModel
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/dagraph/node_model.rb
Instance Method Summary collapse
- #child? ⇒ Boolean
- #child_of?(node) ⇒ Boolean
- #children_at_depth(depth) ⇒ Object
- #children_to_hash(depth: nil) ⇒ Object
- #direct_child_of?(node) ⇒ Boolean
- #direct_parent_of?(node) ⇒ Boolean
- #leaf? ⇒ Boolean
- #parent_of?(node) ⇒ Boolean
- #parents_to_hash(depth: nil) ⇒ Object
- #root? ⇒ Boolean
- #self_and_children ⇒ Object
Instance Method Details
#child? ⇒ Boolean
65 66 67 |
# File 'lib/dagraph/node_model.rb', line 65 def child? !root? end |
#child_of?(node) ⇒ Boolean
46 47 48 49 |
# File 'lib/dagraph/node_model.rb', line 46 def child_of?(node) return false if node.nil? node.parent_of?(self) end |
#children_at_depth(depth) ⇒ Object
33 34 35 |
# File 'lib/dagraph/node_model.rb', line 33 def children_at_depth(depth) self.class.where id: child_edges.where(hops: depth - 1).select(:child_id) end |
#children_to_hash(depth: nil) ⇒ Object
29 30 31 |
# File 'lib/dagraph/node_model.rb', line 29 def children_to_hash(depth: nil) graph_to_hash children, :direct_parents, depth: depth end |
#direct_child_of?(node) ⇒ Boolean
56 57 58 59 |
# File 'lib/dagraph/node_model.rb', line 56 def direct_child_of?(node) return false if node.nil? node.direct_parent_of?(self) end |
#direct_parent_of?(node) ⇒ Boolean
51 52 53 54 |
# File 'lib/dagraph/node_model.rb', line 51 def direct_parent_of?(node) return false if node.nil? direct_children.include?(node) end |
#leaf? ⇒ Boolean
69 70 71 |
# File 'lib/dagraph/node_model.rb', line 69 def leaf? child_edges.empty? end |
#parent_of?(node) ⇒ Boolean
41 42 43 44 |
# File 'lib/dagraph/node_model.rb', line 41 def parent_of?(node) return false if node.nil? children.include?(node) end |
#parents_to_hash(depth: nil) ⇒ Object
25 26 27 |
# File 'lib/dagraph/node_model.rb', line 25 def parents_to_hash(depth: nil) graph_to_hash parents, :direct_children, depth: depth end |
#root? ⇒ Boolean
61 62 63 |
# File 'lib/dagraph/node_model.rb', line 61 def root? parent_edges.empty? end |
#self_and_children ⇒ Object
37 38 39 |
# File 'lib/dagraph/node_model.rb', line 37 def self_and_children self.class.where(id: self).or(self.class.where(id: children)) end |