Class: GEXF::Node
Instance Attribute Summary collapse
Instance Method Summary
collapse
#[], #[]=, #attr_values, #attributes, included, #set_attr_by_id
Constructor Details
#initialize(id, graph, opts = {}) ⇒ Node
Returns a new instance of Node.
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/gexf/node.rb', line 9
def initialize(id, graph, opts={})
@graph = graph
@id = id_type(id)
@label = opts[:label] || @id
@collection = graph.nodes
@attr_values = {}
set_attributes(opts.fetch(:attributes, {}))
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
5
6
7
|
# File 'lib/gexf/node.rb', line 5
def id
@id
end
|
#label ⇒ Object
Returns the value of attribute label.
5
6
7
|
# File 'lib/gexf/node.rb', line 5
def label
@label
end
|
Instance Method Details
#connect_to(target, opts = {}) ⇒ Object
21
22
23
24
|
# File 'lib/gexf/node.rb', line 21
def connect_to(target, opts={})
graph.nodes << target
graph.create_edge(self, target, opts)
end
|
#connections ⇒ Object
32
33
34
|
# File 'lib/gexf/node.rb', line 32
def connections
graph.edges[id].to_a
end
|
#create_and_connect_to(target_attr, opts = {}) ⇒ Object
26
27
28
29
30
|
# File 'lib/gexf/node.rb', line 26
def create_and_connect_to(target_attr, opts={})
node = graph.create_node(target_attr)
connect_to(node, opts)
node
end
|
#incoming_connections ⇒ Object
36
37
38
|
# File 'lib/gexf/node.rb', line 36
def incoming_connections
connections.select { |edge| edge.target_id == id }
end
|
#outgoing_connections ⇒ Object
40
41
42
|
# File 'lib/gexf/node.rb', line 40
def outgoing_connections
connections.select { |edge| edge.source_id == id }
end
|
#to_hash ⇒ Object
44
45
46
|
# File 'lib/gexf/node.rb', line 44
def to_hash
{:id => id, :label => label}
end
|