Class: Vertex
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#paths ⇒ Object
Returns the value of attribute paths.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_edge(edge, vertex) ⇒ Object
- #each(&block) ⇒ Object (also: #each_outgoing)
- #each_incoming(&block) ⇒ Object
- #eql?(obj) ⇒ Boolean (also: #==)
- #fully_qualified_name(delimiter) ⇒ Object
- #get_edge(edge) ⇒ Object (also: #[])
- #hash ⇒ Object
-
#initialize(name, type, namespace = []) ⇒ Vertex
constructor
A new instance of Vertex.
- #remove_edge(edge, vertex) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, type, namespace = []) ⇒ Vertex
Returns a new instance of Vertex.
10 11 12 13 14 15 16 17 18 |
# File 'lib/graph/vertex.rb', line 10 def initialize name, type, namespace=[] @name = name @type = type @namespace = Namespace.new namespace @paths = Array.new @outgoing = Hash.new @incoming = Hash.new end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/graph/vertex.rb', line 8 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
8 9 10 |
# File 'lib/graph/vertex.rb', line 8 def namespace @namespace end |
#paths ⇒ Object
Returns the value of attribute paths.
8 9 10 |
# File 'lib/graph/vertex.rb', line 8 def paths @paths end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/graph/vertex.rb', line 8 def type @type end |
Instance Method Details
#add_edge(edge, vertex) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/graph/vertex.rb', line 26 def add_edge edge, vertex @outgoing[edge] = Set.new if !@outgoing.has_key? edge @outgoing[edge] << vertex vertex.add_incoming_edge edge, self end |
#each(&block) ⇒ Object Also known as: each_outgoing
38 39 40 |
# File 'lib/graph/vertex.rb', line 38 def each &block @outgoing.each &block end |
#each_incoming(&block) ⇒ Object
43 44 45 |
# File 'lib/graph/vertex.rb', line 43 def each_incoming &block @incoming.each &block end |
#eql?(obj) ⇒ Boolean Also known as: ==
47 48 49 50 51 52 53 54 |
# File 'lib/graph/vertex.rb', line 47 def eql? obj self.class.eql?(obj.class) && self.name.eql?(obj.name) && self.namespace.eql?(obj.namespace) && Set.new(self.each.to_a).eql?(Set.new(obj.each.to_a)) && self.paths.eql?(obj.paths) && self.type.eql?(obj.type) end |
#fully_qualified_name(delimiter) ⇒ Object
61 62 63 64 65 |
# File 'lib/graph/vertex.rb', line 61 def fully_qualified_name delimiter ns = self.namespace.join delimiter ns << delimiter if ns != '' ns + self.name end |
#get_edge(edge) ⇒ Object Also known as: []
20 21 22 23 |
# File 'lib/graph/vertex.rb', line 20 def get_edge edge @outgoing[edge] = Set.new if !@outgoing.has_key? edge @outgoing[edge] end |
#hash ⇒ Object
57 58 59 |
# File 'lib/graph/vertex.rb', line 57 def hash @name.hash end |
#remove_edge(edge, vertex) ⇒ Object
33 34 35 36 |
# File 'lib/graph/vertex.rb', line 33 def remove_edge edge, vertex @outgoing[edge].delete vertex vertex.remove_incoming_edge edge, self end |
#to_s ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/graph/vertex.rb', line 67 def to_s string = fully_qualified_name '::' string += "~#{type}\n" @outgoing.each do |edge, set| string << "\t#{edge.to_s}: [ " set.each do |v| string << "#{v.namespace.to_s}#{'::' if v.namespace.to_s != ''}#{v.name.to_s}," end string << "]\n" end return string.chomp end |