aoc-helper/lib/tasks/new_day.rb

28 lines
862 B
Ruby
Raw Normal View History

2022-12-02 18:57:54 +01:00
require "tty-prompt"
require "tty-file"
require "ostruct"
2022-12-02 19:42:16 +01:00
require_relative("templates")
2022-12-02 18:57:54 +01:00
def new_day(prompt, day)
input = prompt.multiline("Example input").join("")
print input
result = prompt.ask("Example result")
day_name = "day_#{day}"
2022-12-02 19:42:16 +01:00
TTY::File.create_dir(day_name)
TTY::File.create_file("#{day_name}/data")
TTY::File.create_file("#{day_name}/impl.rb", IMPL_RB)
TTY::File.create_file("#{day_name}/run.rb", RUN_RB)
TTY::File.create_file("#{day_name}/test.rb", TEST_RB)
2022-12-02 18:57:54 +01:00
TTY::File.replace_in_file "#{day_name}/run.rb", /%day_name%/, day_name
TTY::File.replace_in_file "#{day_name}/test.rb", /%day_name%/, day_name
TTY::File.replace_in_file "#{day_name}/test.rb", /%example_result%/, result
TTY::File.replace_in_file "#{day_name}/test.rb", /%example_input%/, input
puts "Done - run with:"
puts "ruby #{day_name}/test.rb"
2022-12-02 19:42:16 +01:00
end