Class: Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/AnalyzedClass.rb

Instance Method Summary collapse

Constructor Details

#initialize(keyword = "", name = "", type = "") ⇒ Variable

Returns a new instance of Variable.



116
117
118
119
120
# File 'lib/AnalyzedClass.rb', line 116

def initialize (keyword="", name="", type="")
	@keyword = keyword
	@name = name
	@type = type
end

Instance Method Details

#beginningIndex(line) ⇒ Object



199
200
201
202
203
204
205
206
207
# File 'lib/AnalyzedClass.rb', line 199

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

#keywordObject



130
131
132
# File 'lib/AnalyzedClass.rb', line 130

def keyword
	@keyword
end

#nameObject



122
123
124
# File 'lib/AnalyzedClass.rb', line 122

def name
	@name
end

#typeObject



126
127
128
# File 'lib/AnalyzedClass.rb', line 126

def type
	@type
end

#variableForLine(line) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/AnalyzedClass.rb', line 134

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

#variableKeyword(line) ⇒ Object



209
210
211
212
213
214
# File 'lib/AnalyzedClass.rb', line 209

def variableKeyword (line)
	if line.include? "var "
		return "var"
	end
	return "let"
end

#variableName(index, line) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/AnalyzedClass.rb', line 216

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

#variableType(line, variableName) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/AnalyzedClass.rb', line 147

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