Class: IndexHTMLFile

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

Instance Method Summary collapse

Constructor Details

#initialize(formGenerator) ⇒ IndexHTMLFile

Returns a new instance of IndexHTMLFile.



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

def initialize(formGenerator)
       @formGenerator = formGenerator
	@indexHTMLString = ""
end

Instance Method Details

#addAnalysisFilesTableObject



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/IndexHTMLFile.rb', line 139

def addAnalysisFilesTable
    @indexHTML.puts "<h4>COVERAGE BY FILES</h4>"
    @indexHTML.puts "<table cellpadding=\"0\" cellspacing=\"10\" col width=\"600\">"
    @indexHTML.puts "<tr>"
    @indexHTML.puts "<th>File</th>"
    @indexHTML.puts "<th>Functions</th>"
    @indexHTML.puts "<th>Lines</th>"
    @indexHTML.puts "</tr>"
    @indexHTML.puts @indexHTMLString
    @indexHTML.puts "</table>"
end

#addAnalysisItem(analyzedClass, 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
41
42
43
# File 'lib/IndexHTMLFile.rb', line 17

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

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

       numFunctions, numFunctionsTested, percFunctions = funcStats analyzedClass
       color = colorForValidLinePercentage percFunctions

       @indexHTMLString += "\n<td align=\"left\" bgcolor=\"#{color}\">"
       @indexHTMLString += "\n#{percFunctions}% (#{numFunctionsTested}/#{numFunctions})"
       @indexHTMLString += "\n</td>"

       numLinesTested = analyzedClass.numberOfLinesTested
       numLines = analyzedClass.numberOfLines
       percLines = ((Float(numLinesTested) / Float(numLines)) * 100).round
       color = colorForValidLinePercentage percLines

       @indexHTMLString += "\n<td align=\"left\" bgcolor=\"#{color}\">"
       @indexHTMLString += "\n#{percLines}% (#{numLinesTested}/#{numLines})"
       @indexHTMLString += "\n</td>"
end

#addCoverageTableObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/IndexHTMLFile.rb', line 58

def addCoverageTable
    @indexHTML.puts "<h4>OVERALL COVERAGE</h4>"
    @indexHTML.puts "<table cellpadding=\"0\" cellspacing=\"10\" bgcolor=\"#E8E8E8\" width=\"100%\">"
    @indexHTML.puts "<tr>"
    @indexHTML.puts "<th>class</th>"
    @indexHTML.puts "<th>function</th>"
    @indexHTML.puts "<th>lines</th>"
    @indexHTML.puts "</tr>"
    
    @indexHTML.puts "<tr>"

    percClassesTested = ((Float(@formGenerator.classesTested) / Float(@formGenerator.numClasses)) * 100).round
    color = colorForValidLinePercentage percClassesTested

    @indexHTML.puts "<td align=\"center\">"
    @indexHTML.puts "<font color=\"#{color}\">#{percClassesTested}%    (#{@formGenerator.classesTested}/#{@formGenerator.numClasses})</font>"
    @indexHTML.puts "</td>"

    numLinesTested, numFunctionsTested = @formGenerator.functionsTested
    percFunctionsTested = ((Float(numFunctionsTested) / Float(@formGenerator.numFunc)) * 100).round
    color = colorForValidLinePercentage percFunctionsTested

    @indexHTML.puts "<td align=\"center\">"
    @indexHTML.puts "<font color=\"#{color}\">#{percFunctionsTested}%    (#{numFunctionsTested}/#{@formGenerator.numFunc})</font>"
    @indexHTML.puts "</td>"

    percLinesTested = ((Float(numLinesTested) / Float(@formGenerator.totalLines)) * 100).round
    color = colorForValidLinePercentage percLinesTested
    
    @indexHTML.puts "<td align=\"center\">"
    @indexHTML.puts "<font color=\"#{color}\">#{percLinesTested}%    (#{numLinesTested}/#{@formGenerator.totalLines})</font>"
    @indexHTML.puts "</td>"
    
    @indexHTML.puts "</tr>"
    
    @indexHTML.puts "</table>"
end

#addTotalStatsTableObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/IndexHTMLFile.rb', line 96

def addTotalStatsTable
    @indexHTML.puts "<h4>OVERALL STATS</h4>"
    @indexHTML.puts "<table cellpadding=\"0\" cellspacing=\"10\" width=\"200\">"

    @indexHTML.puts "<tr>"
    @indexHTML.puts "<td align=\"left\">"
    @indexHTML.puts "Total files:"
    @indexHTML.puts "</td>"
    @indexHTML.puts "<td align=\"left\">"
    @indexHTML.puts "#{@formGenerator.numProjectFiles}"
    @indexHTML.puts "</td>"
    @indexHTML.puts "</tr>"

    @indexHTML.puts "<tr>"
    @indexHTML.puts "<td align=\"left\">"
    @indexHTML.puts "Total test files:"
    @indexHTML.puts "</td>"
    @indexHTML.puts "<td align=\"left\">"
    @indexHTML.puts "#{@formGenerator.numTestFiles}"
    @indexHTML.puts "</td>"
    @indexHTML.puts "</tr>"

    @indexHTML.puts "<tr>"
    @indexHTML.puts "<td align=\"left\">"
    @indexHTML.puts "Total classes:"
    @indexHTML.puts "</td>"
    @indexHTML.puts "<td align=\"left\">"
    @indexHTML.puts "#{@formGenerator.numClasses}"
    @indexHTML.puts "</td>"
    @indexHTML.puts "</tr>"

    @indexHTML.puts "<tr>"
    @indexHTML.puts "<td align=\"left\">"
    @indexHTML.puts "Total functions:"
    @indexHTML.puts "</td>"
    @indexHTML.puts "<td align=\"left\">"
    @indexHTML.puts "#{@formGenerator.numFunc}"
    @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("#{@formGenerator.analysisDirectory}/index.html", "w+")
end

#colorForValidLinePercentage(percentage) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/IndexHTMLFile.rb', line 151

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

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

    if percentage < 65
       return "#FF4D4D" # Red 
    end
end

#endWritingObject



165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/IndexHTMLFile.rb', line 165

def endWriting
	@indexHTML.puts "<HTML>"
       @indexHTML.puts "<HEAD>"
       @indexHTML.puts "<style> table { border: 1px solid; } </style>"
       @indexHTML.puts "</HEAD>"
       @indexHTML.puts "<BODY>"
	addCoverageTable
	addTotalStatsTable
       addAnalysisFilesTable
	@indexHTML.puts "</BODY></HTML>"
	@indexHTML.close()
end

#funcStats(analyzedClass) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/IndexHTMLFile.rb', line 45

def funcStats (analyzedClass)

    numFunctionsTested = analyzedClass.testedFunctions.count
    numFunctions = analyzedClass.functions.count

    if numFunctionsTested == 0 or numFunctions == 0
        return 0, 0, 0
    end

    percFunctions = ((Float(numFunctionsTested) / Float(numFunctions)) * 100).round
    return numFunctions, numFunctionsTested, percFunctions
end