Class: AdventOfCode::Commands::Download

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

Instance Method Summary collapse

Constructor Details

#initialize(year:, day:) ⇒ Download

Returns a new instance of Download.



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

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

Instance Method Details

#executeObject

Raises:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/advent_of_code_cli/commands/download.rb', line 14

def execute
  raise MissingCookieError unless cookie_present? && cookie

  say("Fetching input...")
  input = fetch_input

  unless Dir.exist?("inputs")
    say("Creating inputs directory...")
    Dir.mkdir("inputs")
  end

  say("Writing input to #{input_file_name}...")
  create_file(input_file_name, input)

  say("Done!", :green)
end