class IndexHTMLFile
Public Class Methods
new(formGenerator)
click to toggle source
# File lib/IndexHTMLFile.rb, line 8 def initialize(formGenerator) @formGenerator = formGenerator @indexHTMLString = "" end
Public Instance Methods
addAnalysisFilesTable()
click to toggle source
# 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)
click to toggle source
# 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
addCoverageTable()
click to toggle source
# 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
addTotalStatsTable()
click to toggle source
# 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
beginWriting()
click to toggle source
# File lib/IndexHTMLFile.rb, line 13 def beginWriting @indexHTML = File.new("#{@formGenerator.analysisDirectory}/index.html", "w+") end
colorForValidLinePercentage(percentage)
click to toggle source
# 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
endWriting()
click to toggle source
# 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)
click to toggle source
# 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