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
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
51 52 53 |
# File 'lib/aoc_rb/app.rb', line 51 def self.exit_on_failure? false end |
Instance Method Details
#bootstrap(year = options[:year], day = options[:day]) ⇒ Object
84 85 86 |
# File 'lib/aoc_rb/app.rb', line 84 def bootstrap(year = [:year], day = [:day]) AocRb::Puzzle.create_templates(year, day) end |
#exec(year = options[:year], day = options[:day]) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/aoc_rb/app.rb', line 105 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
59 60 61 62 |
# File 'lib/aoc_rb/app.rb', line 59 def fetch(year = [:year], day = [:day]) fetch_input(year, day) fetch_instructions(year, day) end |
#fetch_input(year = options[:year], day = options[:day]) ⇒ Object
68 69 70 |
# File 'lib/aoc_rb/app.rb', line 68 def fetch_input(year = [:year], day = [:day]) AocRb::PuzzleInput.download(year, day) end |
#fetch_instructions(year = options[:year], day = options[:day]) ⇒ Object
76 77 78 |
# File 'lib/aoc_rb/app.rb', line 76 def fetch_instructions(year = [:year], day = [:day]) AocRb::Puzzle.fetch_instructions(year, day) end |
#output(year = options[:year], day = options[:day]) ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/aoc_rb/app.rb', line 133 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
160 161 162 163 |
# File 'lib/aoc_rb/app.rb', line 160 def prep(year = [:year], day = [:day]) fetch(year, day) bootstrap(year, day) end |
#spec(year = options[:year], day = options[:day]) ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/aoc_rb/app.rb', line 147 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 |