Class: AocRb::App

Inherits:
Thor
  • Object
show all
Defined in:
lib/aoc_rb/app.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/aoc_rb/app.rb', line 32

def self.exit_on_failure?
  false
end

Instance Method Details

#bootstrap(year = options[:year], day = options[:day]) ⇒ Object



65
66
67
# File 'lib/aoc_rb/app.rb', line 65

def bootstrap(year = options[:year], day = options[:day])
  AocRb::Puzzle.create_templates(year, day)
end

#exec(year = options[:year], day = options[:day]) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/aoc_rb/app.rb', line 86

def exec(year = options[:year], day = options[:day])
  input = AocRb::PuzzleInput.load(year, day)
  puzzle = AocRb::PuzzleSource.create_puzzle(year, day, input)

  level = Puzzle.instructions_exist?(year, day, :part_2) ? 2 : 1
  puts "#{year} Day #{day}"
  solution = PuzzleSource.run_part("part #{level}") { puzzle.send("part_#{level}") }

  puts "Submit solution? #{solution} (y/N)"
  submit = STDIN.gets.chomp.downcase
  puts "We said #{submit}"

  if submit == "y"
    if PuzzleSolution.submit(level, year, day, solution)
      puts "Correct!"

      if level == 1
        puts "Downloading part 2!"
        fetch_instructions(year, day)
      end
    end
  end
end

#fetch(year = options[:year], day = options[:day]) ⇒ Object



40
41
42
43
# File 'lib/aoc_rb/app.rb', line 40

def fetch(year = options[:year], day = options[:day])
  fetch_input(year, day)
  fetch_instructions(year, day)
end

#fetch_input(year = options[:year], day = options[:day]) ⇒ Object



49
50
51
# File 'lib/aoc_rb/app.rb', line 49

def fetch_input(year = options[:year], day = options[:day])
  AocRb::PuzzleInput.download(year, day)
end

#fetch_instructions(year = options[:year], day = options[:day]) ⇒ Object



57
58
59
# File 'lib/aoc_rb/app.rb', line 57

def fetch_instructions(year = options[:year], day = options[:day])
  AocRb::Puzzle.fetch_instructions(year, day)
end

#output(year = options[:year], day = options[:day]) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/aoc_rb/app.rb', line 114

def output(year = options[:year], day = options[:day])
  input = AocRb::PuzzleInput.load(year, day)
  puzzle = AocRb::PuzzleSource.create_puzzle(year, day, input)

  AocRb::PuzzleSource.run_part('part 1') { puzzle.part_1 }
  puts
  AocRb::PuzzleSource.run_part('part 2') { puzzle.part_2 }
end

#prep(year = options[:year], day = options[:day]) ⇒ Object



141
142
143
144
# File 'lib/aoc_rb/app.rb', line 141

def prep(year = options[:year], day = options[:day])
  fetch(year, day)
  bootstrap(year, day)
end

#spec(year = options[:year], day = options[:day]) ⇒ Object



128
129
130
131
132
133
134
135
# File 'lib/aoc_rb/app.rb', line 128

def spec(year = options[:year], day = options[:day])
  if options[:all]
    Kernel.exec( "bundle exec rspec" )
  else
    spec_dir = File.join("spec", year.to_s, AocRb::Puzzle.padded(day))
    Kernel.exec( "bundle exec rspec #{spec_dir}" )
  end
end