Class: MOSAIK::Graph::Vertex
- Inherits:
-
Object
- Object
- MOSAIK::Graph::Vertex
- Extended by:
- T::Sig
- Defined in:
- lib/mosaik/graph/vertex.rb
Overview
Vertex in the graph
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#edges ⇒ Object
readonly
Returns the value of attribute edges.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #add_edge(to, attributes = {}) ⇒ Object
- #find_edge(to, attributes = {}) ⇒ Object
- #find_edges(to) ⇒ Object
- #find_or_add_edge(to, attributes = {}) ⇒ Object
-
#initialize(id, attributes = {}) ⇒ Vertex
constructor
A new instance of Vertex.
- #inspect ⇒ Object
- #remove_edge(id, edge = nil) ⇒ Object
Constructor Details
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
20 21 22 |
# File 'lib/mosaik/graph/vertex.rb', line 20 def attributes @attributes end |
#edges ⇒ Object (readonly)
Returns the value of attribute edges.
17 18 19 |
# File 'lib/mosaik/graph/vertex.rb', line 17 def edges @edges end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/mosaik/graph/vertex.rb', line 14 def id @id end |
Instance Method Details
#add_edge(to, attributes = {}) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/mosaik/graph/vertex.rb', line 30 def add_edge(to, attributes = {}) edge = Edge.new(attributes) T.must(edges[to]) << edge edge end |
#find_edge(to, attributes = {}) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/mosaik/graph/vertex.rb', line 44 def find_edge(to, attributes = {}) if attributes.empty? T.must(edges[to]).first else T.must(edges[to]).find { |edge| attributes.all? { |k, v| edge.attributes[k] == v } } end end |
#find_edges(to) ⇒ Object
39 40 41 |
# File 'lib/mosaik/graph/vertex.rb', line 39 def find_edges(to) T.must(edges[to]) end |
#find_or_add_edge(to, attributes = {}) ⇒ Object
53 54 55 |
# File 'lib/mosaik/graph/vertex.rb', line 53 def find_or_add_edge(to, attributes = {}) find_edge(to, attributes) || add_edge(to, attributes) end |
#inspect ⇒ Object
67 68 69 |
# File 'lib/mosaik/graph/vertex.rb', line 67 def inspect "#<#{self.class.name} id=#{id} attributes=#{attributes.map { |k, v| "#{k}: #{v}" }.join(', ')} edges=#{edges.size}>" end |
#remove_edge(id, edge = nil) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/mosaik/graph/vertex.rb', line 58 def remove_edge(id, edge = nil) if edge.nil? edges.delete(id) else T.must(edges[id]).delete(edge) end end |