#!/usr/bin/env ruby require_relative 'LineDeterminator' require_relative 'IndexHTMLFile' require_relative 'AnalysisHTMLFile' class FormGenerator def initialize(searchDirectoryArg, outputDirectory) @analysisDirectory = "SwiftStyleGuideValidator" if outputDirectory != nil @analysisDirectory = "#{outputDirectory}/#{@analysisDirectory}" end @filesDir = "AnalysisFiles" @searchDirectoryArg = "." if searchDirectoryArg != nil @searchDirectoryArg = searchDirectoryArg @searchDirectoryArg = searchDirectoryArg.chomp("/") end end def generateForm if directoryHasSwiftFiles == true if File.directory?(@analysisDirectory) FileUtils.rm_rf(@analysisDirectory) end Dir.mkdir(@analysisDirectory) @IndexHTMLFile = IndexHTMLFile.new(@analysisDirectory) @IndexHTMLFile.beginWriting counter = 0 Dir.glob("#{@searchDirectoryArg}/**/*.swift") do |item| next if item == '.' or item == '..' addItem item counter += 1 if counter % 50 == 0 print "Files processed: #{counter}\r" end end puts @IndexHTMLFile.endWriting else puts "No Swift files found in directory #{@searchDirectoryArg}" end end def addItem (item) analysisFile = AnalysisHTMLFile.new("#{@analysisDirectory}/#{@filesDir}", item) analysisFile.beginWriting f = File.open(item, "r") f.each_line do |line| analysisFile.addLine (line) end f.close @IndexHTMLFile.addAnalysisItem (analysisFile) analysisFile.endWriting end def directoryHasSwiftFiles hasSwiftFiles = false Dir.glob("#{@searchDirectoryArg}/**/*.swift") do |item| next if item == '.' or item == '..' hasSwiftFiles = true break end hasSwiftFiles end end