Class: Arb::Files::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/arb/files/input.rb

Class Method Summary collapse

Class Method Details

.download(year:, day:, notify_exists: true) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/arb/files/input.rb', line 9

def self.download(year:, day:, notify_exists: true)
  Dir.mkdir("input") unless Dir.exist?("input")
  year_directory = File.join("input", year)
  Dir.mkdir(year_directory) unless Dir.exist?(year_directory)
  file_path = File.join(year_directory, "#{day}.txt")

  if File.exist?(file_path)
    puts "Already exists: #{file_path}" if notify_exists
  else
    aoc_api = Api::Aoc.new(cookie: ENV["AOC_COOKIE"])
    response = aoc_api.input(year:, day:)

    File.write(file_path, response)
  end

  file_path
end

.path(year:, day:) ⇒ Object



4
5
6
7
# File 'lib/arb/files/input.rb', line 4

def self.path(year:, day:)
  year_directory = File.join("input", year)
  File.join(year_directory, "#{day}.txt")
end