advent 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c0c39c2988dbc38f5b3131ddf89f6bd401a40a43b1d9bfc6abdf1c95209f337
4
- data.tar.gz: 7e118fad809b0b052fc7bf3bb52f3076e610a083efba687f1474a5fe8904ee9f
3
+ metadata.gz: 44488f23b0a385b7060d3a2d64d6538dc1e738bbd8600bcc405e1735ace44ff2
4
+ data.tar.gz: aa26c72769ec2cc0eeb05bf4ed67e3619470e7e1e7e77465c0b19c69b65abe2b
5
5
  SHA512:
6
- metadata.gz: 23e3da22b885aab74015af7120f1645e4c069f960f68f5bf30d72c2559b815cd8ee03fdcbb6de4784ccb99c7e4e0d992a156e83dedd38905013e0f028e174de4
7
- data.tar.gz: d554cded9c2cf182aec0ef74d40638471c4f34994ca9e97e5d1d7c860d69b1f1ebad74d17be99d6764a5bc2dc5d437aff23420faa52807955ffe4a5b97bb3260
6
+ metadata.gz: 8be6f552d4fd5930143da51281cf204b7e93f680358578927094f97dde8443d1d5c4307641286edf14fa2454fde7058abd2a2422afe107d4a857b1bdfdd5129b
7
+ data.tar.gz: 51575d6fd1d772627c00e199c69f07c4069429787345fa239312effbeac090604c35bf9ab3c1dada8a13de0e75c8a41c83afccfe91723507eb06c36ee6692f8d
@@ -3,31 +3,31 @@
3
3
  class Advent::CLI::Solver
4
4
  PARTS = [1, 2]
5
5
 
6
- def initialize(command, root_path:, year:, day:)
6
+ def initialize(command, year:, day:)
7
7
  @command = command
8
- @root_path = root_path
9
8
  @year = year
10
9
  @day = day
11
10
  end
12
11
 
13
12
  def solve
14
- if in_year_directory?
15
- require @root_path.join(solution_file_name).to_s
13
+ if @command.in_year_directory?
14
+ require @command.root_path.join(solution_file_name).to_s
16
15
  else
17
- require @root_path.join(@year.to_s, solution_file_name)
16
+ require @command.root_path.join(@year.to_s, solution_file_name)
18
17
  end
19
18
 
20
19
  solution = Object.const_get(solution_class_name).new
21
20
 
22
21
  PARTS.each do |n|
23
22
  method_name = "part#{n}".to_sym
24
- result = if solution.respond_to?(method_name)
25
- solution.public_send(method_name)
26
- else
27
- "Missing"
23
+
24
+ result, colour = if solution.respond_to?(method_name)
25
+ [solution.public_send(method_name), :green]
28
26
  end
29
27
 
30
- @command.say "Part #{n}: #{result}"
28
+ result, colour = ["Missing", :red] if result.nil?
29
+
30
+ @command.say "Part #{n}: #{result}", colour, true
31
31
  end
32
32
  end
33
33
 
@@ -40,9 +40,4 @@ class Advent::CLI::Solver
40
40
  def solution_class_name
41
41
  "Day#{@day}"
42
42
  end
43
-
44
- def in_year_directory?
45
- dir = @root_path.basename.to_s
46
- dir =~ /^20[0-9]{2}/
47
- end
48
43
  end
data/lib/advent/cli.rb CHANGED
@@ -6,31 +6,56 @@ require "thor"
6
6
 
7
7
  module Advent
8
8
  class CLI < Thor
9
+ include Thor::Actions
10
+
9
11
  class_option :root_path, default: Dir.pwd, hide: true, check_default_type: false
10
12
 
13
+ def initialize(*args)
14
+ super
15
+
16
+ self.destination_root = root_path
17
+ source_paths << File.expand_path("templates", __dir__)
18
+ end
19
+
11
20
  def self.exit_on_failure?
12
21
  true
13
22
  end
14
23
 
24
+ no_commands do
25
+ def in_year_directory?
26
+ dir = root_path.basename.to_s
27
+ dir =~ /^20[0-9]{2}/
28
+ end
29
+
30
+ def root_path
31
+ @_root_path ||= if options.root_path.is_a?(Pathname)
32
+ options.root_path
33
+ else
34
+ Pathname.new(options.root_path)
35
+ end
36
+ end
37
+ end
38
+
39
+ desc "generate YEAR DAY or generate DAY in a year directory", "Generate a new solution for YEAR and DAY"
40
+ def generate(year_or_day, day = nil)
41
+ destination = if in_year_directory?
42
+ "day#{year_or_day}.rb"
43
+ else
44
+ "#{year_or_day}/day#{day}.rb"
45
+ end
46
+
47
+ template "solution.rb.tt", destination, context: binding
48
+ end
49
+
15
50
  desc "solve YEAR DAY", "Solve your solution for YEAR and DAY"
16
51
  def solve(year, day)
17
52
  require "advent/cli/solver"
18
- Solver.new(self, root_path: root_path, year: year, day: day).solve
53
+ Solver.new(self, year: year, day: day).solve
19
54
  end
20
55
 
21
56
  desc "version", "Prints the current version of Advent"
22
57
  def version
23
58
  say Advent::VERSION
24
59
  end
25
-
26
- private
27
-
28
- def root_path
29
- @_root_path ||= if options.root_path.is_a?(Pathname)
30
- options.root_path
31
- else
32
- Pathname.new(options.root_path)
33
- end
34
- end
35
60
  end
36
61
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "advent"
4
+
5
+ class Day<%= day %> < Advent::Solution
6
+ def part1(input: load_input)
7
+ end
8
+
9
+ def part2(input: load_input)
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Advent
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Grieve
@@ -40,6 +40,7 @@ files:
40
40
  - lib/advent/cli.rb
41
41
  - lib/advent/cli/solver.rb
42
42
  - lib/advent/solution.rb
43
+ - lib/advent/templates/solution.rb.tt
43
44
  - lib/advent/version.rb
44
45
  homepage: https://github.com/dnlgrv/advent-rb
45
46
  licenses: