Module: ActsAsGraphDiagram::Node::InstanceMethods

Defined in:
lib/acts_as_graph_diagram/node.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#add_connection(node, directed: false, comment: '', figure: 0) ⇒ Edge

Creates a new undirected connection record for this instance to connect the passed object.

Parameters:

  • node (Node)
  • directed (Boolean) (defaults to: false)
  • comment (String) (defaults to: '')
  • figure (Integer) (defaults to: 0)

Returns:



55
56
57
58
59
60
61
# File 'lib/acts_as_graph_diagram/node.rb', line 55

def add_connection(node, directed: false, comment: '', figure: 0)
  Edge.where(destination: node,
             directed: directed,
             departure: self,
             comment: comment,
             figure: figure).first_or_create!
end

#add_departure(node, comment: '', figure: 0) ⇒ Edge

Creates a new departure record for this instance to connect the passed object.

Parameters:

  • node (Node)
  • comment (String) (defaults to: '')
  • figure (Integer) (defaults to: 0)

Returns:



43
44
45
46
47
# File 'lib/acts_as_graph_diagram/node.rb', line 43

def add_departure(node, comment: '', figure: 0)
  behinds.select_departures(node)
         .where(comment: comment, figure: figure)
         .first_or_create!
end

#add_destination(node, comment: '', figure: 0) ⇒ Edge

Creates a new destination record for this instance to connect the passed object.

Parameters:

  • node (Node)
  • comment (String) (defaults to: '')
  • figure (Integer) (defaults to: 0)

Returns:



32
33
34
35
36
# File 'lib/acts_as_graph_diagram/node.rb', line 32

def add_destination(node, comment: '', figure: 0)
  aheads.select_destinations(node)
        .where(comment: comment, figure: figure)
        .first_or_create!
end

#connecting?(node) ⇒ Boolean

Returns true if this instance is connecting the object passed as an argument.

Parameters:

Returns:

  • (Boolean)


109
110
111
# File 'lib/acts_as_graph_diagram/node.rb', line 109

def connecting?(node)
  node.connecting_count.positive?
end

#connecting_countInteger

Returns the number of objects this instance is following.

Returns:

  • (Integer)


115
116
117
# File 'lib/acts_as_graph_diagram/node.rb', line 115

def connecting_count
  Edge.select_connections(self).count
end

#get_connection(node) ⇒ Edge

Returns a undirected node record for the current instance.

Parameters:

Returns:



95
96
97
# File 'lib/acts_as_graph_diagram/node.rb', line 95

def get_connection(node)
  Edge.select_connections(node).first
end

#get_departure(node) ⇒ Edge

Returns a departure node record for the current instance.

Parameters:

Returns:



81
82
83
# File 'lib/acts_as_graph_diagram/node.rb', line 81

def get_departure(node)
  behinds.select_departures(node).first
end

#get_destination(node) ⇒ Edge

Returns a destination node record for the current instance.

Parameters:

Returns:



67
68
69
# File 'lib/acts_as_graph_diagram/node.rb', line 67

def get_destination(node)
  aheads.select_destinations(node).first
end

#remove_connection(node) ⇒ Edge|nil

Deletes the undirected record if it exists.

Parameters:

Returns:



102
103
104
# File 'lib/acts_as_graph_diagram/node.rb', line 102

def remove_connection(node)
  get_connection(node).try(:destroy)
end

#remove_departure(node) ⇒ Edge|nil

Deletes the destination record if it exists.

Parameters:

Returns:



88
89
90
# File 'lib/acts_as_graph_diagram/node.rb', line 88

def remove_departure(node)
  get_departure(node).try(:destroy)
end

#remove_destination(node) ⇒ Edge|nil

Deletes the destination record if it exists.

Parameters:

Returns:



74
75
76
# File 'lib/acts_as_graph_diagram/node.rb', line 74

def remove_destination(node)
  get_destination(node).try(:destroy)
end