Class: Statesman::Diagram

Inherits:
Object
  • Object
show all
Defined in:
lib/statesman/diagram.rb,
lib/statesman/diagram/version.rb

Constant Summary collapse

VERSION =
'0.1.3'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(name:, graph:) ⇒ Diagram

Returns a new instance of Diagram.

Parameters:

  • name (String)
    • name of the diagram.

  • graph (Hash)
    • list of vertices and edges.



7
8
9
10
# File 'lib/statesman/diagram.rb', line 7

def initialize(name:, graph:)
  @name  = name
  @graph = graph
end

Instance Method Details

#to_dotString

Returns diagram in DOT format.

Returns:

  • (String)

    diagram in DOT format.



13
14
15
# File 'lib/statesman/diagram.rb', line 13

def to_dot
  format("digraph %{name} {\n  %{body}\n}", name: @name, body: dot_body.join("\n  "))
end

#to_png(file_name = nil) ⇒ Object



17
18
19
20
21
22
# File 'lib/statesman/diagram.rb', line 17

def to_png(file_name = nil)
  file_name ||= @name
  file_name += '.png'

  build_png(file_name)
end