Class: NetworkDrawer::Diagram

Inherits:
Object
  • Object
show all
Defined in:
lib/network_drawer/diagram.rb

Overview

Replesent of source file

Constant Summary collapse

TOP_LAYER =
:networkdrawertop
DEFAULT_OPTIONS =
{}
ELELMENT_KEYS =
[:layers, :nodes, :connections]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, dest_file, options = {}) ⇒ Diagram

Returns a new instance of Diagram.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/network_drawer/diagram.rb', line 15

def initialize(source, dest_file, options = {})
  @source = source ? source : {}
  @dest_file = dest_file
  @options = DEFAULT_OPTIONS.merge(options)
  @title = @options[:title] ? @options[:title] :
    File.basename(@dest_file, '.*')
  @nodes = {}
  @layers = {}
  @connections = []
  @style = options[:style]
  @gv = Gviz.new(@title)
end

Class Method Details

.draw(source, dest_file, options = {}) ⇒ Object



10
11
12
13
# File 'lib/network_drawer/diagram.rb', line 10

def self.draw(source, dest_file, options = {})
  diagram = new(source, dest_file, options)
  diagram.draw
end

Instance Method Details

#drawObject



28
29
30
31
32
33
34
35
36
# File 'lib/network_drawer/diagram.rb', line 28

def draw
  @layers = create_layers
  @connections = create_connections
  draw_elements

  @gv.global(layout: @options[:layout] ? @options[:layout] : :dot)
  @gv.global(@source.dup.delete_if { |k, _| ELELMENT_KEYS.include?(k) })
  @gv.save @dest_file, @options[:format]
end