Class: Docit::SystemGraph::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/docit/system_graph/graph.rb

Constant Summary collapse

VERSION =
"1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(framework: "rails") ⇒ Graph

Returns a new instance of Graph.



12
13
14
15
16
# File 'lib/docit/system_graph/graph.rb', line 12

def initialize(framework: "rails")
  @framework = framework
  @nodes = {}
  @edges = {}
end

Instance Attribute Details

#edgesObject (readonly)

Returns the value of attribute edges.



10
11
12
# File 'lib/docit/system_graph/graph.rb', line 10

def edges
  @edges
end

#frameworkObject (readonly)

Returns the value of attribute framework.



10
11
12
# File 'lib/docit/system_graph/graph.rb', line 10

def framework
  @framework
end

#nodesObject (readonly)

Returns the value of attribute nodes.



10
11
12
# File 'lib/docit/system_graph/graph.rb', line 10

def nodes
  @nodes
end

Instance Method Details

#add_edge(edge) ⇒ Object



22
23
24
25
26
27
# File 'lib/docit/system_graph/graph.rb', line 22

def add_edge(edge)
  return if edge.source == edge.target
  return unless nodes.key?(edge.source) && nodes.key?(edge.target)

  edges[edge.id] ||= edge
end

#add_node(node) ⇒ Object



18
19
20
# File 'lib/docit/system_graph/graph.rb', line 18

def add_node(node)
  nodes[node.id] ||= node
end

#to_hObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/docit/system_graph/graph.rb', line 29

def to_h
  node_values = nodes.values
  edge_values = edges.values

  {
    version: VERSION,
    generated_at: Time.now.utc.iso8601,
    framework: framework,
    nodes: node_values.map(&:to_h),
    edges: edge_values.map(&:to_h),
    stats: stats(node_values, edge_values)
  }
end