Class: JsDependency::Mermaid::Root
- Inherits:
-
Object
- Object
- JsDependency::Mermaid::Root
- Defined in:
- lib/js_dependency/mermaid/root.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#orientation ⇒ Object
Returns the value of attribute orientation.
Instance Method Summary collapse
- #add(parent, child) ⇒ Object
- #export(name_level: 1, src_path: nil) ⇒ String
- #export_header ⇒ String
- #export_nodes(name_level: 1, src_path: nil) ⇒ Array<String>
-
#initialize(orientation = "LR") ⇒ Root
constructor
A new instance of Root.
Constructor Details
#initialize(orientation = "LR") ⇒ Root
Returns a new instance of Root.
11 12 13 14 |
# File 'lib/js_dependency/mermaid/root.rb', line 11 def initialize(orientation = "LR") @orientation = orientation @list = [] end |
Instance Attribute Details
#list ⇒ Object (readonly)
Returns the value of attribute list.
8 9 10 |
# File 'lib/js_dependency/mermaid/root.rb', line 8 def list @list end |
#orientation ⇒ Object
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
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
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_header ⇒ 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>
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 |