Class: Advent::Input
- Inherits:
-
Object
- Object
- Advent::Input
- Defined in:
- lib/advent/input.rb
Instance Method Summary collapse
- #download(session, http = Net::HTTP) ⇒ Object
- #exist? ⇒ Boolean
- #file_path ⇒ Object
-
#initialize(dir, day:) ⇒ Input
constructor
A new instance of Input.
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) = CGI::Cookie.new("session", session) response = http.get_response(input_url, {"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
19 20 21 |
# File 'lib/advent/input.rb', line 19 def exist? File.exist? file_path end |
#file_path ⇒ Object
15 16 17 |
# File 'lib/advent/input.rb', line 15 def file_path @dir.join(".day#{@day}.input.txt") end |