Class: SimpleHdGraph::Renderer::PlantUML::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/simple-hd-graph/renderer/plantuml/context.rb

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



5
6
7
# File 'lib/simple-hd-graph/renderer/plantuml/context.rb', line 5

def initialize
  @resource_renderer = Resource.new
end

Instance Method Details

#indent_resource(resource) ⇒ String

Parameters:

  • resource (String)

Returns:

  • (String)


45
46
47
48
49
# File 'lib/simple-hd-graph/renderer/plantuml/context.rb', line 45

def indent_resource(resource)
  @resource_renderer.render(resource).lines.map { |line|
    "  #{line}"
  }.join
end

#render(node) ⇒ Object

Parameters:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/simple-hd-graph/renderer/plantuml/context.rb', line 12

def render(node)
  resources =
    if node.resources.size > 0
      node.resources.map { |resource|
        indent_resource(resource)
      }.join
    end
  relations =
    if node.relations.size > 0
      node.relations.map { |relation|
        render_relation(relation)
      }.join("\n")
    end
  depends =
    if node.depends.size > 0
      node.depends.map { |depending|
        render_depends(depending)
      }.join("\n")
    end

  <<~EOD.gsub(/^$\n/, "")
    rectangle "#{node.alias}" as #{node.id} {
    #{resources}
    #{relations}
    }
    #{depends}
  EOD
end

#render_depends(depending) ⇒ String

:reek:UtilityFunction

Parameters:

  • depending (Hash)

Returns:

  • (String)


66
67
68
69
# File 'lib/simple-hd-graph/renderer/plantuml/context.rb', line 66

def render_depends(depending)
  depender, dependee = depending.to_a.first
  "#{depender} -|> #{dependee}"
end

#render_relation(relation) ⇒ String

:reek:UtilityFunction

Parameters:

  • relation (Hash)

Returns:

  • (String)


56
57
58
59
# File 'lib/simple-hd-graph/renderer/plantuml/context.rb', line 56

def render_relation(relation)
  depender, dependee = relation.to_a.first
  "  #{depender} -d-|> #{dependee}"
end