More automization

This commit is contained in:
Alexander Munch-Hansen 2019-10-21 20:16:37 +02:00
parent f11bd7c456
commit f961d478b6
2 changed files with 108 additions and 65 deletions

115
lol.rb
View File

@ -3,12 +3,17 @@ require_relative 'sorting_algos'
require_relative 'Type'
require_relative 'functional_functions'
require_relative 'Filter'
require_relative 'pdf-parser'
# Hi! Steffan was here...
prim_class, container, class_fields, container_params, container_methods_maggie = parse "ferry.pdf"
name = prim_class
container_class = container
container_obj = "ferries"
name = "Ferry"
container_class = "Harbour"
to_string_template = "0 1 x 2 meter"
sorting_one = Type.new("String", "Name")
@ -20,6 +25,45 @@ sorting_three.comparator = "<"
sorting_filters = [sorting_one, sorting_two, sorting_three]
print(class_fields)
params = [*class_fields.map! {|x| {:type => x.split(" ")[0], :name => x.split(" ")[1].capitalize}}]
container_methods = [
*container_methods_maggie.map! {|x|
{
:return_type => x.type,
:name => x.name.start_with?("print") ? x.name + "pls" : x.name ,
:params => [*x.parameters.split(",").map! {|y|
{
:type => y.split(" ")[0].strip,
:name => y.split(" ")[1].strip
}
}],
:method_type => nil
}
}
]
container_methods[0][:method_type] = add_method(container_obj, "f")
container_methods[1][:method_type] = find_all(container_obj, "Length", "<", "#{name}", "maxLength")
container_methods[2][:method_type] = find_best_with_extra_parameter(container_obj, "Length", ">", "#{name}", "Name", ".equals", "Name", "int")
container_methods[4][:method_type] = func_find_all(container_obj, "Width", [Filter.new("min", ">="), Filter.new("max", "<=")])
container_methods[5][:method_type] = find_whatever_of_variable(container_obj, "Name", [Filter.new("Name", ".equals")], "sum", "Length")
container_params = [{:type => "String", :name => "Name"}]
container_fields = [ {:type => "ArrayList<#{name}>", :name => container_obj}]
driver_methods = [{:name => "smallFerries", :parameters => [{:type => "int"}], :print => true},
{:name => "longFerry", :parameters => [{:type => "String"}], :print => true},
{:name => "printHarbour", :parameters => [], :print => false},
{:name => "findFerries", :parameters => [{:type => "int"}, {:type => "int"}], :print => true },
{:name => "findLength", :parameters => [{:type => "String"}], :print => true}]
driver_params = [{:type => "String"}]
def construct_class(name_of_class, parameters, to_string_template, sorting_filters)
sorting_string = compare_to(sorting_filters)
@ -41,8 +85,7 @@ def construct_class(name_of_class, parameters, to_string_template, sorting_filte
end
(0...parameters.length).each do |x|
pls = "\" + #{parameters[x][:name]} + \""
to_string_template.sub! "#{x}", pls
to_string_template.sub! "#{x}", "\" + #{parameters[x][:name]} + \""
end
"
public class #{name_of_class} implements Comparable<#{name_of_class}> {
@ -169,76 +212,18 @@ public class #{name} {
end
container_methods = [
{
:return_type => "void",
:name => "addFerry",
:params => [{
:type => "Ferry",
:name => "f"
}],
:method_type => add_method(container_obj, "f")
},
{
:return_type => "ArrayList<Ferry>",
:name => "smallFerries",
:params => [{
:type => "int",
:name => "maxLength"
}],
:method_type => find_all(container_obj, "Length", " < ", "#{name}", "maxLength")
},
{
:return_type => "#{name}",
:name => "longFerry",
:params => [{
:type => "String",
:name => "Name"
}],
:method_type => find_best_with_extra_parameter(container_obj, "Length", " > ", "#{name}", "Name", ".equals", "Name", "int")
},
{
:return_type => "List<#{name}>",
:name => "findFerries",
:params => [{
:type => "int",
:name => "min",
},
{
:type => "int",
:name => "max"
}],
:method_type => func_find_all(container_obj, "Width", [Filter.new("min", ">="), Filter.new("max", "<=")])
},
{
:return_type => "int",
:name => "findLength",
:params => [{
:type => "String",
:name => "Name"
}],
:method_type => find_whatever_of_variable(container_obj, "Name", [Filter.new("Name", ".equals")], "sum", "Length")
}
]
file = File.open("#{name}.java", "w")
params = [{:type => "String", :name => "Name"}, {:type => "int", :name => "Length"}, {:type => "int", :name => "Width"}]
file.puts(construct_class name, params, to_string_template, sorting_filters)
file.close
another_another_file = File.open("#{container_class}.java", "w")
another_another_file.puts(construct_container(container_class, [{:type => "String", :name => "Name"}], [ {:type => "ArrayList<#{name}>", :name => container_obj}], container_methods, container_obj))
another_another_file.puts(construct_container(container_class, container_params, container_fields, container_methods, container_obj))
another_another_file.close
# TODO: When creating find algorithms, remember to add a space or two (lol for consistency) for <, >, <=, >=
puts "fucking please"
another_file = File.open("TestDriver.java", "w")
another_file.puts(construct_driver name, params, [{:name => "smallFerries", :parameters => [{:type => "int"}], :print => true},
{:name => "longFerry", :parameters => [{:type => "String"}], :print => true},
{:name => "printHarbour", :parameters => [], :print => false},
{:name => "findFerries", :parameters => [{:type => "int"}, {:type => "int"}], :print => true },
{:name => "findLength", :parameters => [{:type => "String"}], :print => true}], container_class, [{:type => "String"}])
another_file.puts(construct_driver name, params, driver_methods, container_class, driver_params)
another_file.close

58
pdf-parser.rb Normal file
View File

@ -0,0 +1,58 @@
require 'pdf-reader'
require_relative 'Method_desc'
def parse(exam_text)
reader = PDF::Reader.new(exam_text)
text = reader.pages[0].text.split "\n"
content = text.slice(3, 15).map {|x| x.split " "}.map {|x| x.filter {|y| y.length > 1 and y.strip != "*"} }.filter {|x| x.length > 0}
prim_class = content[0][0]
if content[0].length == 1
container = content[1][0]
else
container = content[0][1]
end
container_params = content.slice(2, content.length-1).filter { |x|
unless x[0].include? "("
x[0]
end
}.map {|x| x[0].strip}
container_methods = content.slice(2, content.length-1).filter { |x|
if x[0].include? "("
x[0]
end
}.map {|x| x[0].strip}
class_fields = content.slice(3, content.length-1).filter { |x|
(x.length > 1) and (not x[1].include? "(")
}.map {|x| x[1].strip}
if content[4].length == 1
tmp = content[4][0].strip
class_fields += [tmp]
end
#print(content.slice(0, content.length-1))
regex = /\A(\S+) (\w+)\((.*)\)\Z/
container_methods.map! do |x|
matches = x.match(regex)
Method_desc.new(*matches.captures)
end
return prim_class, container, class_fields, container_params, container_methods
end
parse("ferry.pdf")