Class: AdventOfCode::Commands::Example::New

Inherits:
Command
  • Object
show all
Defined in:
lib/advent_of_code_cli/commands/example/new.rb

Instance Method Summary collapse

Constructor Details

#initialize(day:, name:) ⇒ New

Returns a new instance of New.



7
8
9
10
# File 'lib/advent_of_code_cli/commands/example/new.rb', line 7

def initialize(day:, name:)
  @name = name
  super(day: day)
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/advent_of_code_cli/commands/example/new.rb', line 12

def execute
  unless Dir.exist?("examples")
    say("Creating examples directory...")
    Dir.mkdir("examples")
  end

  unless Dir.exist?("examples/#{day_string}")
    say("Creating examples/#{day_string} directory...")
    Dir.mkdir("examples/#{day_string}")
  end

  if File.exist?(example_file_name)
    raise ExampleAlreadyExistsError,
          "could not create example file because file #{example_file_name} already exists"
  end

  say("Creating #{example_file_name}...")
  create_file(example_file_name)

  say("Creating #{example_expected_file_name}...")
  create_file(example_expected_file_name, expected_file_contents)

  say "Done!", :green
end