Module: Diagram::Nomenclature

Defined in:
lib/diagram/nomenclature.rb

Class Method Summary collapse

Class Method Details

.inheritance(nomenclature, options = {}) ⇒ Object


4
5
6
7
8
9
10
11
12
13
# File 'lib/diagram/nomenclature.rb', line 4

def inheritance(nomenclature, options = {})
  options[:name] ||= "#{nomenclature.name.to_s.underscore}-inheritance"
  graph = Diagram::Graph.new(options.delete(:name), :digraph, rank_dir: 'RL', edge: { color: '#999999' })
  nomenclature.list.each do |item|
    next unless item.depth < 4
    graph.node item.name, font_color: '#002255', color: '#002255'
    graph.arrow(item.name, item.parent.name, head: :empty) if item.parent?
  end
  graph
end

.inheritance_all(nomenclature, options = {}) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/diagram/nomenclature.rb', line 15

def inheritance_all(nomenclature, options = {})
  options[:name] ||= "#{nomenclature.name.to_s.underscore}-inheritance"
  nomenclature.list.each do |item|
    next unless item.children.any?
    graph = Diagram::Graph.new("#{nomenclature.name.to_s.underscore}-#{item.name}", :digraph, rank_dir: 'RL', edge: { color: '#999999' })
    graph.node item.name, font_color: '#002266', color: '#002255'
    item.children(recursively: false).each do |i|
      graph.node i.name, font_color: '#002255', color: '#002255'
      graph.arrow(i.name, item.name, head: :empty)
    end
    graph.arrow(item.name, item.parent.name, head: :empty) if item.parent?
    path = Rails.root.join('doc', 'diagrams', nomenclature.name.to_s).join(*item.self_and_parents.reverse.map(&:name).join('-'))
    graph.write(path: path.to_s)
  end
end