-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_solution.rb
More file actions
executable file
·78 lines (67 loc) · 1.63 KB
/
Copy pathinit_solution.rb
File metadata and controls
executable file
·78 lines (67 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env ruby
require 'fileutils'
require './aochelper.rb'
require './solution_template.rb'
class AOCSolutionInitializer
attr_accessor :dry_run
def initialize(day=nil, year=nil)
@helper = AOCHelper.new
@day = day || @helper.current_day(true)
@year = year || @helper.current_year
@dry_run = false
end
def init_solution
mk_proj_dir
checkout_proj_branch
create_solution_file
download_input_file
end
def path
"#{@year}/#{@day}"
end
def branch
"#{@year}-#{@day}"
end
def mk_proj_dir
puts "Making solution directory at #{path}"
if !@dry_run
FileUtils.mkdir_p path
end
end
def checkout_proj_branch
puts "Checking out branch #{branch}"
if !@dry_run
`git checkout -b #{branch}`
end
end
def create_solution_file
filepath = "#{path}/solution.rb"
puts "Creating solution file at #{filepath}"
if !@dry_run
File.open(filepath, 'w') {|f| f.write create_template @day }
end
puts "Adding executable permission to #{filepath}"
if !@dry_run
FileUtils.chmod "a+x", filepath
end
end
def download_input_file
filepath = "#{path}/input.txt"
samplefilepath = "#{path}/sampleinput.txt"
puts "Downloading input data and saving to #{filepath}"
puts "Creating empty file at #{samplefilepath}"
if !@dry_run
File.open(filepath, 'w') {|f| f.write @helper.get_input_data(@day.to_i.to_s, @year)}
FileUtils.touch(samplefilepath)
end
end
end
if __FILE__ == $0
ai = nil
if !ARGV[0]
ai = AOCSolutionInitializer.new
else
ai = AOCSolutionInitializer.new ARGV[0]
end
ai.init_solution
end