Class: NetCrawl::Output::Dot

Inherits:
Object
  • Object
show all
Defined in:
lib/netcrawl/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



6
7
8
# File 'lib/netcrawl/output/dot.rb', line 6

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

Instance Method Details

#to_sObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/netcrawl/output/dot.rb', line 10

def to_s
  str = "graph NetCrawl {\n"
  @output.to_list.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 and @connections.include?([peer_name, host].sort)
        @connections << [peer_name, host].sort
        labels = ''
        labels = "[headlabel=\"#{peer.dst.to_s}\" taillabel=\"#{peer.src.to_s}\"]" if CFG.dot.linklabel
        str << INDENT + INDENT + id(host) + ' -- ' + id(peer_name) + labels + "\n"
      end
    end
  end
  str << "}\n"
  str
end