Class: Aspen::Renderers::GexfRenderer
Instance Attribute Summary
#environment, #statements
Instance Method Summary
collapse
#initialize
Instance Method Details
#nodes ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/aspen/renderers/gexf_renderer.rb', line 21
def nodes
statements.flat_map(&:nodes).map do |node|
attrs = node.attributes.map do |k, v|
"#{k}=\"#{v}\""
end.join(" ")
<<~GEXF
<node id="#{node.nickname}" label="#{node.label}" #{attrs}>
GEXF
end
end
|
#relationships ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/aspen/renderers/gexf_renderer.rb', line 32
def relationships
statements.map.with_index do |st, id|
if st.is_a? Aspen::CustomStatement
next else
<<~GEXF
<edge id="#{id}" source="#{st.origin.nickname}" target="#{st.target.nickname}" label="#{st.edge.label}">
GEXF
end
end.compact
end
|
#render ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/aspen/renderers/gexf_renderer.rb', line 5
def render
joiner = "\n "
<<~GEXF
<gexf xmlns="http://www.gexf.net/1.2draft" version="1.2">
<graph mode="static" defaultedgetype="directed">
<nodes>
#{nodes.map(&:strip).join(joiner)}
</nodes>
<edges>
#{relationships.map(&:strip).join(joiner)}
</edges>
</graph>
</gexf>
GEXF
end
|