Class: AdventOfCode::Commands::Example::Solve

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

Instance Method Summary collapse

Constructor Details

#initialize(day:, name:) ⇒ Solve

Returns a new instance of Solve.



9
10
11
12
# File 'lib/advent_of_code_cli/commands/example/solve.rb', line 9

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

Instance Method Details

#executeObject



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

def execute
  raise MissingExampleError unless File.exist?(example_file_name)
  raise MissingExampleError unless File.exist?(example_expected_file_name)
  raise MissingSolutionError unless File.exist?(solution_file_name)

  say "Reading input..."
  input = File.readlines(example_file_name, chomp: true)

  say "Loading solution..."
  load(solution_file_name)

  module_name = "Day#{day_string}"

  say "\nRunning part one with example #{@name}..."
  solution(module_name, "one", input)

  say "\nRunning part two with example #{@name}..."
  solution(module_name, "two", input)

  say "\nDone!", :green
end