Class: AocRb::App
- Inherits:
-
Thor
- Object
- Thor
- AocRb::App
- Defined in:
- lib/aoc_rb/app.rb
Class Method Summary collapse
Instance Method Summary collapse
- #bootstrap(year = options[:year], day = options[:day]) ⇒ Object
- #exec(year = options[:year], day = options[:day]) ⇒ Object
- #fetch(year = options[:year], day = options[:day]) ⇒ Object
- #fetch_input(year = options[:year], day = options[:day]) ⇒ Object
- #fetch_instructions(year = options[:year], day = options[:day]) ⇒ Object
- #output(year = options[:year], day = options[:day]) ⇒ Object
- #prep(year = options[:year], day = options[:day]) ⇒ Object
- #spec(year = options[:year], day = options[:day]) ⇒ Object
Class Method Details
.exit_on_failure? ⇒ 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 = [:year], day = [: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 = [:year], day = [: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 = [:year], day = [: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 = [:year], day = [: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 = [:year], day = [: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 = [:year], day = [: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 = [:year], day = [: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 = [:year], day = [:day]) if [: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 |