#!/usr/bin/env ruby
class IndexHTMLFile
def initialize(directory)
@directory = directory
@totalLines = 0
@totalValidLines = 0
@totalInvalidLines = 0
@indexHTMLString = ""
end
def beginWriting
@indexHTML = File.new("#{@directory}/index.html", "w+")
end
def addAnalysisItem (analysisFile)
@totalLines += analysisFile.totalLines
@totalInvalidLines += analysisFile.invalidLines
@totalValidLines += analysisFile.validLines
htmlFileName = analysisFile.name
htmlFileName = htmlFileName.gsub(".swift", "")
htmlFileName = htmlFileName.gsub("./", "")
@indexHTMLString += "
"
@indexHTMLString += "\n"
@indexHTMLString += "\n#{htmlFileName}.html"
@indexHTMLString += "\n | "
@indexHTMLString += "\n"
@indexHTMLString += "\n#{analysisFile.invalidLines}"
@indexHTMLString += "\n | "
validLinePercentage = ((analysisFile.invalidLines / Float(analysisFile.totalLines) - 1) * -100).round
color = colorForValidLinePercentage validLinePercentage
@indexHTMLString += "\n"
@indexHTMLString += "\n#{validLinePercentage}%"
@indexHTMLString += "\n | "
@indexHTMLString += "\n
"
end
def addTotalStatsTable
@indexHTML.puts ""
@indexHTML.puts ""
@indexHTML.puts "Total Lines | "
@indexHTML.puts "Invalid Lines | "
@indexHTML.puts "Valid Lines | "
@indexHTML.puts "Percent Valid | "
@indexHTML.puts "
"
@indexHTML.puts ""
@indexHTML.puts ""
@indexHTML.puts "#{@totalLines}"
@indexHTML.puts " | "
@indexHTML.puts ""
@indexHTML.puts "#{@totalInvalidLines}"
@indexHTML.puts " | "
@indexHTML.puts ""
@indexHTML.puts "#{@totalValidLines}"
@indexHTML.puts " | "
validLinePercentage = ((@totalInvalidLines / Float(@totalLines) - 1) * -1 * 100).round
color = colorForValidLinePercentage validLinePercentage
@indexHTML.puts ""
@indexHTML.puts "#{validLinePercentage}%"
@indexHTML.puts " | "
@indexHTML.puts "
"
@indexHTML.puts "
"
end
def addAnalysisFilesTable
@indexHTML.puts ""
@indexHTML.puts ""
@indexHTML.puts "File | "
@indexHTML.puts "Invalid Statements | "
@indexHTML.puts "Percent Valid | "
@indexHTML.puts "
"
@indexHTML.puts @indexHTMLString
@indexHTML.puts "
"
end
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
def endWriting
@indexHTML.puts ""
addTotalStatsTable
addAnalysisFilesTable
@indexHTML.puts ""
@indexHTML.close()
end
end