#!/usr/bin/env ruby class AnalyzedClass def initialize @functions = Array.new @variables = Array.new @testedFunctions = Array.new @numberOfLines = 0 end def addFunction (name, numLines) @functions.push(Function.new(name, numLines)) end def addVariable variable @variables.push(variable) end def addTestedFunction function if !(isTestedFunctionInArray function.name) @testedFunctions.push(function) end end def isTestedFunctionInArray functionName for function in @testedFunctions if function.name == functionName return true end end return false end def isLineWithTestedFunction line for function in @testedFunctions if line.include? function.name return true end end return false end def functions @functions end def variables @variables end def testedFunctions @testedFunctions end def name @name end def numberOfLines=(numberOfLines) @numberOfLines = numberOfLines end def numberOfLines @numberOfLines end def numberOfLinesTested count = 0 for function in @testedFunctions count += function.numLines end return count end def name=(name) name = name.strip @name = name end def fileName @fileName end def fileName=(fileName) @fileName = fileName end def variablesWithType varsWithType = Array.new for vari in @variables if vari.type != nil varsWithType.push(vari) end end return varsWithType end end class Function def initialize (name, numLines) @name = name @numLines = numLines end def name @name end def numLines @numLines end end class Variable def initialize (keyword="", name="", type="") @keyword = keyword @name = name @type = type end def name @name end def type @type end def keyword @keyword end def variableForLine (line) if !(line.include? "let ") and !(line.include? "var ") return nil end index = beginningIndex line variableKeyword = variableKeyword line varName = variableName index, line type = variableType line, varName return Variable.new variableKeyword, varName, type end def variableType (line, variableName) if variableName == nil or line.include? "[" return nil end if (line.include? "=" and line.include? "(") if line.include? "." indexDot = line.index(".") indexParen = line.index("(") if indexParen < indexDot index = line.index("=") temp = line[index+1..-1] temp = temp.strip temp = temp.slice(0..(temp.index("(") - 1)).strip if temp.index("(") != 0 type = temp.strip return type end end else index = line.index("=") temp = line[index+1..-1] type = temp.slice(0..(temp.index("(") - 1)).strip return type end elsif line.include? ":" index = line.index(":") temp = line[index+1..-1].strip if temp.include? "!" temp = temp[0..-2] end if temp.include? "?" temp = temp[0..-2] end if temp.include? "]" temp = temp[0..temp.index("]")] end if temp.include? " " temp = temp[0..temp.index(" ")] end return temp end return nil end def beginningIndex (line) index = 0 if line.include? "var " index = (line.index("var ") + 4) elsif line.include? "let " index = (line.index("let ") + 4) end return index end def variableKeyword (line) if line.include? "var " return "var" end return "let" end def variableName (index, line) varName = "" if line.include? ":" and !(line.include? "=") varName = line.slice(index..(line.index(":")-1)) elsif temp = line temp = temp[index..-1] whiteSpaceIndex = temp.index(" ") equalsIndex = temp.index("=") if equalsIndex == nil equalsIndex = 9999 end colonIndex = temp.index(":") endStringSliceIndex = whiteSpaceIndex if whiteSpaceIndex > equalsIndex endStringSliceIndex = equalsIndex end varName = temp.slice(0..endStringSliceIndex) if varName.include? ":" varName = varName.slice(0..varName.index(":")-1) end end return varName.strip end end