Class: IndexHTMLFile

Inherits:
Object
  • Object
show all
Defined in:
lib/IndexHTMLFile.rb

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ IndexHTMLFile

Returns a new instance of IndexHTMLFile.



5
6
7
8
9
10
11
# File 'lib/IndexHTMLFile.rb', line 5

def initialize(directory)
	@directory = directory
	@totalLines = 0
	@totalValidLines = 0
	@totalInvalidLines = 0
	@indexHTMLString = ""
end

Instance Method Details

#addAnalysisFilesTableObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/IndexHTMLFile.rb', line 76

def addAnalysisFilesTable
    @indexHTML.puts "<table cellpadding=\"0\" cellspacing=\"10\" class=\"table\" bgcolor=\"#E8E8E8\" col width=\"800\">"
    @indexHTML.puts "<tr>"
    @indexHTML.puts "<th>File</th>"
    @indexHTML.puts "<th>Invalid Statements</th>"
    @indexHTML.puts "<th>Percent Valid</th>"
    @indexHTML.puts "</tr>"
    @indexHTML.puts @indexHTMLString
    @indexHTML.puts "</table>"
end

#addAnalysisItem(analysisFile) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/IndexHTMLFile.rb', line 17

def addAnalysisItem (analysisFile)
	@totalLines += analysisFile.totalLines
	@totalInvalidLines += analysisFile.invalidLines
	@totalValidLines += analysisFile.validLines

	htmlFileName = analysisFile.name
	htmlFileName = htmlFileName.gsub(".swift", "")
	htmlFileName = htmlFileName.gsub("./", "")

	@indexHTMLString += "<tr>"
	@indexHTMLString += "\n<td>"
	@indexHTMLString += "\n<a href=\"#{analysisFile.directory.gsub(@directory + "/", "")}/#{analysisFile.name}.html\">#{htmlFileName}.html</a>"
	@indexHTMLString += "\n</td>"
	@indexHTMLString += "\n<td align=\"center\">"
	@indexHTMLString += "\n#{analysisFile.invalidLines}"
	@indexHTMLString += "\n</td>"

       validLinePercentage = ((analysisFile.invalidLines / Float(analysisFile.totalLines) - 1) * -100).round
       color = colorForValidLinePercentage validLinePercentage
	@indexHTMLString += "\n<td align=\"center\" bgcolor=\"#{color}\">"
	@indexHTMLString += "\n#{validLinePercentage}%"
	@indexHTMLString += "\n</td>"
	@indexHTMLString += "\n</tr>"
end

#addTotalStatsTableObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/IndexHTMLFile.rb', line 42

def addTotalStatsTable
    @indexHTML.puts "<table cellpadding=\"0\" cellspacing=\"10\" class=\"table\" bgcolor=\"#E8E8E8\" col width=\"800\">"
    @indexHTML.puts "<tr>"
    @indexHTML.puts "<th>Total Lines</th>"
    @indexHTML.puts "<th>Invalid Lines</th>"
    @indexHTML.puts "<th>Valid Lines</th>"
    @indexHTML.puts "<th>Percent Valid</th>"
    @indexHTML.puts "</tr>"
    
    @indexHTML.puts "<tr>"
    
    @indexHTML.puts "<td align=\"center\">"
    @indexHTML.puts "#{@totalLines}"
    @indexHTML.puts "</td>"
    
    @indexHTML.puts "<td align=\"center\">"
    @indexHTML.puts "#{@totalInvalidLines}"
    @indexHTML.puts "</td>"
    
    @indexHTML.puts "<td align=\"center\">"
    @indexHTML.puts "#{@totalValidLines}"
    @indexHTML.puts "</td>"
    
    validLinePercentage = ((@totalInvalidLines / Float(@totalLines) - 1) * -1 * 100).round
    color = colorForValidLinePercentage validLinePercentage
    @indexHTML.puts "<td align=\"center\" bgcolor=\"#{color}\">"
    @indexHTML.puts "#{validLinePercentage}%"
    @indexHTML.puts "</td>"
    
    @indexHTML.puts "</tr>"
    
    @indexHTML.puts "</table>"
end

#beginWritingObject



13
14
15
# File 'lib/IndexHTMLFile.rb', line 13

def beginWriting
	@indexHTML = File.new("#{@directory}/index.html", "w+")
end

#colorForValidLinePercentage(percentage) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/IndexHTMLFile.rb', line 87

def colorForValidLinePercentage (percentage)
    if percentage >= 95
        return "#52CC52" # Green
    end

    if percentage >= 90 and percentage < 95
       return "yellow"
    end

    if percentage < 90
       return "#FF0000" # Red 
    end
end

#endWritingObject



101
102
103
104
105
106
107
# File 'lib/IndexHTMLFile.rb', line 101

def endWriting
	@indexHTML.puts "<HTML><BODY>"
	addTotalStatsTable
	addAnalysisFilesTable
	@indexHTML.puts "</BODY></HTML>"
	@indexHTML.close()
end