lib/nilac/compile_ruby_methods.rb in nilac-0.0.4.3.9.4 vs lib/nilac/compile_ruby_methods.rb in nilac-0.0.4.3.9.5
- old
+ new
@@ -1,10 +1,50 @@
def compile_ruby_methods(input_file_contents)
# These are some interesting methods that we really miss in Javascript.
# So we have made these methods available
+ def compile_complex_methods(input_file_contents)
+
+ method_map_replacement = {
+
+ ".include" => [".indexOf"," != -1"],
+
+ }
+
+ method_map_replacement.each do |val,key|
+
+ possible_complex_method_calls = input_file_contents.reject {|element| !element.include?(val)}
+
+ possible_complex_method_calls.each do |statement|
+
+ before,after = statement.split(val)
+
+ after,remains = after.split
+
+ if after[-1].eql?(")")
+
+ after = after[0...-1] + key[1] + after[-1]
+
+ elsif after.strip.eql?(after)
+
+ after = after + key[1]
+
+ end
+
+ reconstructed_statement = before + key[0] + after + remains
+
+ input_file_contents[input_file_contents.index(statement)] = reconstructed_statement
+
+ end
+
+ end
+
+ return input_file_contents
+
+ end
+
method_map_replacement = {
".split" => ".split(\" \")",
".join" => ".join()",
@@ -17,11 +57,11 @@
".to_s" => ".toString()",
".reverse" => ".reverse()",
- ".empty?" => ".length == 0",
+ ".empty" => ".length == 0",
".upcase" => ".toUpperCase()",
".downcase" => ".toLowerCase()",
@@ -50,9 +90,11 @@
end
modified_file_contents[index] = line
end
+
+ modified_file_contents = compile_complex_methods(modified_file_contents)
return modified_file_contents
end
\ No newline at end of file