Class: Aoc::Challenge
- Inherits:
-
Object
- Object
- Aoc::Challenge
- Defined in:
- lib/aoc/challenge.rb
Instance Method Summary collapse
-
#initialize(day, year) ⇒ Challenge
constructor
A new instance of Challenge.
- #input ⇒ Object
- #part1 ⇒ Object
- #part2 ⇒ Object
- #part2? ⇒ Boolean
- #url ⇒ Object
Constructor Details
#initialize(day, year) ⇒ Challenge
Returns a new instance of Challenge.
6 7 8 9 |
# File 'lib/aoc/challenge.rb', line 6 def initialize(day, year) @day = day @year = year end |
Instance Method Details
#input ⇒ Object
31 32 33 34 |
# File 'lib/aoc/challenge.rb', line 31 def input session = Aoc::Session.get_session @input ||= Nokogiri::HTML(open("#{url}/input", "Cookie" => "session=#{session}")).text end |
#part1 ⇒ Object
15 16 17 |
# File 'lib/aoc/challenge.rb', line 15 def part1 @part1 ||= content.css('article.day-desc').first.text end |
#part2 ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/aoc/challenge.rb', line 19 def part2 if part2? @part2 ||= content.css('article.day-desc').last.text else "Part 2 not unlocked yet" end end |
#part2? ⇒ Boolean
27 28 29 |
# File 'lib/aoc/challenge.rb', line 27 def part2? content.css('article.day-desc').count > 1 end |
#url ⇒ Object
11 12 13 |
# File 'lib/aoc/challenge.rb', line 11 def url "https://adventofcode.com/#{@year}/day/#{@day}" end |