Class: JsDependency::Mermaid::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/js_dependency/mermaid/root.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orientation = "LR") ⇒ Root

Returns a new instance of Root.

Parameters:

  • orientation (String) (defaults to: "LR")


11
12
13
14
# File 'lib/js_dependency/mermaid/root.rb', line 11

def initialize(orientation = "LR")
  @orientation = orientation
  @list = []
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



8
9
10
# File 'lib/js_dependency/mermaid/root.rb', line 8

def list
  @list
end

#orientationObject

Returns the value of attribute orientation.



7
8
9
# File 'lib/js_dependency/mermaid/root.rb', line 7

def orientation
  @orientation
end

Instance Method Details

#add(parent, child) ⇒ Object

Parameters:

  • parent (String)
  • child (String)


18
19
20
# File 'lib/js_dependency/mermaid/root.rb', line 18

def add(parent, child)
  @list << NodesLink.new(parent, child)
end

#export(name_level: 1, src_path: nil) ⇒ String

Parameters:

  • name_level (Integer) (defaults to: 1)
  • src_path (nil, String) (defaults to: nil)

Returns:

  • (String)


25
26
27
# File 'lib/js_dependency/mermaid/root.rb', line 25

def export(name_level: 1, src_path: nil)
  ([export_header] + export_nodes(name_level: name_level, src_path: src_path)).join("\n")
end

#export_headerString

Returns:

  • (String)


30
31
32
# File 'lib/js_dependency/mermaid/root.rb', line 30

def export_header
  "flowchart #{orientation}"
end

#export_nodes(name_level: 1, src_path: nil) ⇒ Array<String>

Parameters:

  • name_level (Integer) (defaults to: 1)
  • src_path (nil, String) (defaults to: nil)

Returns:

  • (Array<String>)


37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/js_dependency/mermaid/root.rb', line 37

def export_nodes(name_level: 1, src_path: nil)
  nodes_links = if src_path
                  @list.map { |nodes_link| nodes_link.relative_path_from(src_path) }
                else
                  @list
                end
  nodes_links = nodes_links.uniq { |nodes_link| "#{nodes_link.parent}__#{nodes_link.child}" }
  nodes_links = nodes_links.sort_by { |nodes_link| "#{nodes_link.parent}__#{nodes_link.child}" }
  nodes_links.map do |nodes_link|
    "#{nodes_link.parent_module_name(name_level)} --> #{nodes_link.child_module_name(name_level)}"
  end
end