Class: Marmerdo::DomainDiagramGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/marmerdo/domain_diagram_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(output_path:, nodes:, enable_link_extension:) ⇒ DomainDiagramGenerator

Returns a new instance of DomainDiagramGenerator.



3
4
5
6
7
# File 'lib/marmerdo/domain_diagram_generator.rb', line 3

def initialize(output_path:, nodes:, enable_link_extension:)
  @output_path = output_path
  @nodes = nodes
  @enable_link_extension = enable_link_extension
end

Instance Method Details

#generateString

Returns mermaid class diagram.

Returns:

  • (String)

    mermaid class diagram



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/marmerdo/domain_diagram_generator.rb', line 10

def generate
  classes = @nodes.map(&:to_mermaid_str)
  links = @nodes.map do |node|
    node.generate_mermaid_link(@output_path, enable_link_extension: @enable_link_extension)
  end

  relationships = @nodes.flat_map do |node|
    node.relationships.map do |relationship|
      relationship.to_mermaid_str(node.name)
    end
  end

  [
    "classDiagram",
    classes,
    links,
    relationships
  ].flatten.join("\n")
end