Class: Aspen::Renderers::JsonRenderer
Instance Attribute Summary
#environment, #statements
Instance Method Summary
collapse
#initialize
Instance Method Details
#nodes ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/aspen/renderers/json_renderer.rb', line 12
def nodes
statements.flat_map(&:nodes).map do |node|
node.attributes.merge({
id: node.nickname,
label: node.label
})
end
end
|
#relationships ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/aspen/renderers/json_renderer.rb', line 21
def relationships
statements.map.with_index do |st, id|
if st.is_a? Aspen::CustomStatement
next else
{
id: "e#{id}",
source: st.origin.nickname,
target: st.target.nickname,
label: st.edge.label,
reciprocal: st.edge.reciprocal?
}
end
end.compact
end
|
#render ⇒ Object
5
6
7
8
9
10
|
# File 'lib/aspen/renderers/json_renderer.rb', line 5
def render
{
nodes: nodes,
edges: relationships
}.to_json
end
|