Class: Schatz::Output::HTML
Instance Attribute Summary collapse
-
#connections ⇒ Object
Returns the value of attribute connections.
-
#html ⇒ Object
Returns the value of attribute html.
Attributes inherited from Out
Instance Method Summary collapse
- #file_name ⇒ Object
- #generate ⇒ Object
-
#initialize(options = {}) ⇒ HTML
constructor
A new instance of HTML.
- #print(connection) ⇒ Object
- #print_end ⇒ Object
- #print_head ⇒ Object
- #print_hosts ⇒ Object
- #print_links ⇒ Object
- #print_links_table(proxy, links) ⇒ Object
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(={}) @html="" = @connections = [] end |
Instance Attribute Details
#connections ⇒ Object
Returns the value of attribute connections.
4 5 6 |
# File 'lib/schatz/output/html.rb', line 4 def connections @connections end |
#html ⇒ Object
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_name ⇒ Object
25 26 27 |
# File 'lib/schatz/output/html.rb', line 25 def file_name [:file_name].to_s+"_test_"+ Time.now.strftime("%d-%m-%y-%s")+".html" end |
#generate ⇒ Object
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 |
#print(connection) ⇒ Object
10 11 12 |
# File 'lib/schatz/output/html.rb', line 10 def print(connection) @connections << connection end |
#print_end ⇒ Object
64 65 66 |
# File 'lib/schatz/output/html.rb', line 64 def print_end @html << "</body></html>" end |
#print_head ⇒ Object
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 |
#print_hosts ⇒ Object
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 |
#print_links ⇒ Object
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 |
#print_links_table(proxy, links) ⇒ Object
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 |