Class: Aoc::Challenge

Inherits:
Object
  • Object
show all
Defined in:
lib/aoc/challenge.rb

Instance Method Summary collapse

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

#inputObject



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

#part1Object



15
16
17
# File 'lib/aoc/challenge.rb', line 15

def part1
  @part1 ||= content.css('article.day-desc').first.text
end

#part2Object



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

Returns:

  • (Boolean)


27
28
29
# File 'lib/aoc/challenge.rb', line 27

def part2?
  content.css('article.day-desc').count > 1
end

#urlObject



11
12
13
# File 'lib/aoc/challenge.rb', line 11

def url
  "https://adventofcode.com/#{@year}/day/#{@day}"
end