lib/ruby_reads_php.rb in mattfawcett-ruby-reads-php-1.0.0 vs lib/ruby_reads_php.rb in mattfawcett-ruby-reads-php-1.1.0
- old
+ new
@@ -17,17 +17,29 @@
data = parse_file(file)
self
end
def parse_file(file)
- constant_regex = /define\((\s)*('|")((\w|\s)+)('|")(\s)*,(\s)*('|")?((\w|\s)*)('|")(\s)*\);/
+ constant_regex = /define\((\s)*('|")((\w|\s)+)('|")(\s)*,(\s)*(('|")?)([^'"]*)(('|")?)(\s)*\);/
while (line = file.gets)
if line.match(constant_regex)
contant_key = line[constant_regex, 3]
- constant_value = line[constant_regex, 9]
+ constant_value = line[constant_regex, 10]
+ if line[constant_regex, 9].nil?
+ #This value was not wrapped in quotes. cast it to either an integer or a float
+ constant_value = cast_not_string_value(constant_value)
+ end
constants[contant_key] = constant_value
end
end
end
+
+ def cast_not_string_value(value)
+ if value.match(/\./)
+ return value.to_f
+ else
+ return value.to_i
+ end
+ end
end