Class: Marmerdo::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, name:, namespace:, relationships:) ⇒ Node

Returns a new instance of Node.



13
14
15
16
17
18
# File 'lib/marmerdo/node.rb', line 13

def initialize(path:, name:, namespace:, relationships:)
  @path = path
  @name = name.to_sym
  @namespace = namespace&.to_sym
  @relationships = relationships
end

Instance Attribute Details

#nameSymbol (readonly)

Returns:

  • (Symbol)


8
9
10
# File 'lib/marmerdo/node.rb', line 8

def name
  @name
end

#namespaceSymbol? (readonly)

Returns:

  • (Symbol, nil)


10
11
12
# File 'lib/marmerdo/node.rb', line 10

def namespace
  @namespace
end

#pathSymbol (readonly)

Returns:

  • (Symbol)


6
7
8
# File 'lib/marmerdo/node.rb', line 6

def path
  @path
end

#relationshipsObject

Returns the value of attribute relationships.



11
12
13
# File 'lib/marmerdo/node.rb', line 11

def relationships
  @relationships
end

Instance Method Details



32
33
34
35
36
37
38
39
# File 'lib/marmerdo/node.rb', line 32

def generate_mermaid_link(output_path, enable_link_extension:)
  path = enable_link_extension ? @path : Pathname.new(@path).sub_ext("").to_s

  output_dir = Pathname.new(output_path).dirname
  relative_path = Pathname.new(path).relative_path_from(output_dir).to_s
  relative_path = "./#{relative_path}" unless relative_path.start_with?("../")
  "link #{name} \"#{relative_path}\""
end

#to_mermaid_strObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/marmerdo/node.rb', line 20

def to_mermaid_str
  str = "class #{name}"

  return str if namespace.nil?

  [
    "namespace #{namespace} {",
    str,
    "}"
  ].join("\n")
end