Class: Advent::Input

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

Instance Method Summary collapse

Constructor Details

#initialize(dir, day:) ⇒ Input

Returns a new instance of Input.



10
11
12
13
# File 'lib/advent/input.rb', line 10

def initialize(dir, day:)
  @dir = dir
  @day = day
end

Instance Method Details

#download(session, http = Net::HTTP) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/advent/input.rb', line 23

def download(session, http = Net::HTTP)
  session_cookie = CGI::Cookie.new("session", session)
  response = http.get_response(input_url, {"Cookie" => session_cookie.to_s})

  if success?(response)
    FileUtils.mkdir_p file_path.dirname
    File.write file_path, response.body
    true
  else
    false
  end
end

#exist?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/advent/input.rb', line 19

def exist?
  File.exist? file_path
end

#file_pathObject



15
16
17
# File 'lib/advent/input.rb', line 15

def file_path
  @dir.join(".day#{@day}.input.txt")
end