Class: NetworkDrawer::Diagram
- Inherits:
-
Object
- Object
- NetworkDrawer::Diagram
- 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
- #draw ⇒ Object
-
#initialize(source, dest_file, options = {}) ⇒ Diagram
constructor
A new instance of Diagram.
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, = {}) @source = source ? source : {} @dest_file = dest_file @options = DEFAULT_OPTIONS.merge() @title = @options[:title] ? @options[:title] : File.basename(@dest_file, '.*') @nodes = {} @layers = {} @connections = [] @style = [: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, = {}) diagram = new(source, dest_file, ) diagram.draw end |
Instance Method Details
#draw ⇒ Object
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 |