Class: Advent::Cli
- Inherits:
-
Thor
- Object
- Thor
- Advent::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/advent/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #auth ⇒ Object
- #download(year, day) ⇒ Object
- #new(year, day) ⇒ Object
- #solve(path) ⇒ Object
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
6 7 8 |
# File 'lib/advent/cli.rb', line 6 def self.exit_on_failure? true end |
Instance Method Details
#auth ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/advent/cli.rb', line 12 def auth session = [:session] || ask("What is your Advent of Code session value?", echo: false) say "" create_file ".advent_session", session append_to_file ".gitignore", ".advent_session" if File.exist? ".git" end |
#download(year, day) ⇒ Object
21 22 23 |
# File 'lib/advent/cli.rb', line 21 def download(year, day) get "https://adventofcode.com/#{year}/day/#{day}/input", "#{year}/.day#{day}_input.txt", http_headers: http_headers end |
#new(year, day) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/advent/cli.rb', line 26 def new(year, day) self.class.source_root __dir__ template "templates/solution.rb.tt", "#{year}/day#{day}.rb", context: binding template "templates/solution_test.rb.tt", "test/#{year}/day#{day}_test.rb", context: binding end |
#solve(path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/advent/cli.rb', line 34 def solve(path) load path require "active_support/core_ext/object/blank" require "active_support/core_ext/string/inflections" require "pathname" klass = Pathname.new(path).basename(".rb").to_s.classify.constantize part_1 = klass.new.part_1 part_2 = klass.new.part_2 say_status "Part 1", part_1.presence || "No answer", part_1.present? ? :green : :red say_status "Part 2", part_2.presence || "No answer", part_2.present? ? :green : :red end |