Class: Puppet::SimpleGraph::VertexWrapper
- Defined in:
- lib/puppet/simple_graph.rb
Overview
An internal class for handling a vertex’s edges.
Instance Attribute Summary collapse
-
#in ⇒ Object
Returns the value of attribute in.
-
#out ⇒ Object
Returns the value of attribute out.
-
#vertex ⇒ Object
Returns the value of attribute vertex.
Instance Method Summary collapse
-
#add_edge(direction, edge) ⇒ Object
Add an edge to our list.
-
#adjacent(options) ⇒ Object
Find adjacent vertices or edges.
-
#clear ⇒ Object
Remove all references to everything.
-
#edges ⇒ Object
Return all known edges.
-
#has_edge?(direction, vertex) ⇒ Boolean
Test whether we share an edge with a given vertex.
-
#initialize(vertex) ⇒ VertexWrapper
constructor
A new instance of VertexWrapper.
- #inspect ⇒ Object
-
#other_vertex(direction, edge) ⇒ Object
The other vertex in the edge.
-
#remove_edge(direction, edge) ⇒ Object
Remove an edge from our list.
- #to_s ⇒ Object
Constructor Details
#initialize(vertex) ⇒ VertexWrapper
Returns a new instance of VertexWrapper.
21 22 23 24 |
# File 'lib/puppet/simple_graph.rb', line 21 def initialize(vertex) @vertex = vertex @adjacencies = {:in => {}, :out => {}} end |
Instance Attribute Details
#in ⇒ Object
Returns the value of attribute in.
12 13 14 |
# File 'lib/puppet/simple_graph.rb', line 12 def in @in end |
#out ⇒ Object
Returns the value of attribute out.
12 13 14 |
# File 'lib/puppet/simple_graph.rb', line 12 def out @out end |
#vertex ⇒ Object
Returns the value of attribute vertex.
12 13 14 |
# File 'lib/puppet/simple_graph.rb', line 12 def vertex @vertex end |
Instance Method Details
#add_edge(direction, edge) ⇒ Object
Add an edge to our list.
37 38 39 |
# File 'lib/puppet/simple_graph.rb', line 37 def add_edge(direction, edge) opposite_adjacencies(direction, edge) << edge end |
#adjacent(options) ⇒ Object
Find adjacent vertices or edges.
27 28 29 30 31 32 33 34 |
# File 'lib/puppet/simple_graph.rb', line 27 def adjacent() direction = [:direction] || :out [:type] ||= :vertices return send(direction.to_s + "_edges") if [:type] == :edges @adjacencies[direction].keys.reject { |vertex| @adjacencies[direction][vertex].empty? } end |
#clear ⇒ Object
Remove all references to everything.
15 16 17 18 19 |
# File 'lib/puppet/simple_graph.rb', line 15 def clear @adjacencies[:in].clear @adjacencies[:out].clear @vertex = nil end |
#edges ⇒ Object
Return all known edges.
42 43 44 |
# File 'lib/puppet/simple_graph.rb', line 42 def edges in_edges + out_edges end |
#has_edge?(direction, vertex) ⇒ Boolean
Test whether we share an edge with a given vertex.
47 48 49 |
# File 'lib/puppet/simple_graph.rb', line 47 def has_edge?(direction, vertex) return(vertex_adjacencies(direction, vertex).length > 0 ? true : false) end |
#inspect ⇒ Object
83 84 85 |
# File 'lib/puppet/simple_graph.rb', line 83 def inspect { :@adjacencies => @adjacencies, :@vertex => @vertex.to_s }.inspect end |
#other_vertex(direction, edge) ⇒ Object
The other vertex in the edge.
65 66 67 68 69 70 71 |
# File 'lib/puppet/simple_graph.rb', line 65 def other_vertex(direction, edge) case direction when :in; edge.source else edge.target end end |
#remove_edge(direction, edge) ⇒ Object
Remove an edge from our list. Assumes that we’ve already checked that the edge is valid.
75 76 77 |
# File 'lib/puppet/simple_graph.rb', line 75 def remove_edge(direction, edge) opposite_adjacencies(direction, edge).delete(edge) end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/puppet/simple_graph.rb', line 79 def to_s vertex.to_s end |