Class: Aspen::Renderers::GexfRenderer

Inherits:
AbstractRenderer show all
Defined in:
lib/aspen/renderers/gexf_renderer.rb

Instance Attribute Summary

Attributes inherited from AbstractRenderer

#environment, #statements

Instance Method Summary collapse

Methods inherited from AbstractRenderer

#initialize

Constructor Details

This class inherits a constructor from AbstractRenderer

Instance Method Details

#nodesObject



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

#relationshipsObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aspen/renderers/gexf_renderer.rb', line 32

def relationships
  # @todo: Add in Custom Statements
  statements.map.with_index do |st, id|
    if st.is_a? Aspen::CustomStatement
      next # NO OP
    else
      <<~GEXF
        <edge id="#{id}" source="#{st.origin.nickname}" target="#{st.target.nickname}" label="#{st.edge.label}">
      GEXF
    end
  end.compact
end

#renderObject



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