Class: Schatz::Output::HTML

Inherits:
Out
  • Object
show all
Defined in:
lib/schatz/output/html.rb

Instance Attribute Summary collapse

Attributes inherited from Out

#options

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HTML

Returns a new instance of HTML.



5
6
7
8
9
# File 'lib/schatz/output/html.rb', line 5

def initialize(options={})
  @html=""
  @options = options
  @connections = []
end

Instance Attribute Details

#connectionsObject

Returns the value of attribute connections.



4
5
6
# File 'lib/schatz/output/html.rb', line 4

def connections
  @connections
end

#htmlObject

Returns the value of attribute html.



4
5
6
# File 'lib/schatz/output/html.rb', line 4

def html
  @html
end

Instance Method Details

#file_nameObject



25
26
27
# File 'lib/schatz/output/html.rb', line 25

def file_name
  @options[:file_name].to_s+"_test_"+ Time.now.strftime("%d-%m-%y-%s")+".html"
end

#generateObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/schatz/output/html.rb', line 14

def generate
  File.open(file_name,"w+") do |file|
    print_head
    print_hosts
    print_links
    print_end
    file << @html
    @html
  end
end


10
11
12
# File 'lib/schatz/output/html.rb', line 10

def print(connection)
  @connections << connection
end


64
65
66
# File 'lib/schatz/output/html.rb', line 64

def print_end
  @html << "</body></html>"
end


54
55
56
57
58
59
60
61
62
63
# File 'lib/schatz/output/html.rb', line 54

def print_head
  @html << "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'><html lang='en'>
  <head>
  <title>Connection Test Results</title>
  <style type='text/css'>
    .green{background-color:SeaGreen}
    .red  {background-color:Crimson}
  </style>
  </head><body>"
end


29
30
31
32
33
34
35
36
37
# File 'lib/schatz/output/html.rb', line 29

def print_hosts
  @html << "<h3>Conversation Map</h3>"
  @html << "<table>"
  @html << "<tr><th>Number</th><th> IP address</th><th> Port </th><th> Protocol </th><th> Result </th></tr>"
  @connections.select{ |connection| connection.direct? }.each_with_index do |host, index|
    @html << "<tr><td>#{index+1}</td><td>#{host.host}</td><td>#{host.port}</td><td>#{host.scheme}</td><td class='#{host.color}'>#{host.result}</td></tr>"
  end
  @html << "</table><br/><br/>"
end


39
40
41
42
43
# File 'lib/schatz/output/html.rb', line 39

def print_links
  @connections.select{ |connection| connection.link? }.group_by { |connection| connection.proxy}.each do |proxy, links|
    print_links_table(proxy, links)
  end        
end


45
46
47
48
49
50
51
52
53
# File 'lib/schatz/output/html.rb', line 45

def print_links_table(proxy, links)
  @html << "<h3>Intranet Access #{proxy}</h3>"
  @html << "<table>"
  @html << "<tr><th>Number</th><th> Link to page</th><th> Result </th></tr>"
  links.each_with_index do |link, index|
    @html << "<tr><td>#{index+1}</td><td><a href='#{link.scheme}://#{link.host}:#{link.port}'> #{link.scheme}://#{link.host}:#{link.port} </td><td class='#{link.color}'>#{link.result}</td></tr>"
  end
  @html << "</table>"
end