Class: Netdisco::Output::Dot

Inherits:
Object
  • Object
show all
Defined in:
lib/netdisco/output/dot.rb

Constant Summary collapse

INDENT =
" " * 2
DEFAULT_COLOR =
"black"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.output(output) ⇒ Object



8
9
10
# File 'lib/netdisco/output/dot.rb', line 8

def self.output(output)
  new(output).to_s
end

Instance Method Details

#to_sObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/netdisco/output/dot.rb', line 12

def to_s
  str = "graph Netdisco {\n"
  @output.to_a.each do |host|
    host_label = label(host)
    # 调整图形修饰符
    str += INDENT + id(host) + "[label=\"#{host_label}\" color=\"#{color(host_label)}\"]\n"

    if @peers.has_key? host
      @peers[host].each do |peer|
        peer_name = @resolve ? peer.name : peer.ip
        next if (not CFG.dot.bothlinks) && @connections.include?([peer_name, host].sort)
        @connections << [peer_name, host].sort
        labels = ""
        labels = "[headlabel=\"#{peer.dst}\" taillabel=\"#{peer.src}\"]" if CFG.dot.linklabel
        str << INDENT + INDENT + id(host) + " -- " + id(peer_name) + labels + "\n"
      end
    end
  end
  str += "}\n"
  str
end