Sha256: 35fd1b9be8cbae1688ebf2f1d6c3baa2b775cb6fcee526bb1fd745967c586598

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

#!/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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dftsg-0.1.2 lib/FormGenerator.rb
dftsg-0.1.1 lib/FormGenerator.rb