advent 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cdf5d96352bc47ad63cceb8ce3c796fe57a86a00174687ec998b3ad196b408a
4
- data.tar.gz: 4e04dca6d1b461511df17894298587e2457470813c0b6a30f43229ba5e8fc098
3
+ metadata.gz: 44488f23b0a385b7060d3a2d64d6538dc1e738bbd8600bcc405e1735ace44ff2
4
+ data.tar.gz: aa26c72769ec2cc0eeb05bf4ed67e3619470e7e1e7e77465c0b19c69b65abe2b
5
5
  SHA512:
6
- metadata.gz: e4e083b0e213e4180716c2791b163ed510754bfa9b172a31986440e108ae54f68e88813a95aedc6df66ddce445cae340a7979b5ce4bb3907f8b4845906edfd9c
7
- data.tar.gz: cc56db526c42d93f16869a2f05fdf1c8e4f8b2edd10d243fea72d4145cec6264ddc9ecbca1ebdd3901937e17a05d34fbeb7eb2a54458dac6190e2ab1a75bdd04
6
+ metadata.gz: 8be6f552d4fd5930143da51281cf204b7e93f680358578927094f97dde8443d1d5c4307641286edf14fa2454fde7058abd2a2422afe107d4a857b1bdfdd5129b
7
+ data.tar.gz: 51575d6fd1d772627c00e199c69f07c4069429787345fa239312effbeac090604c35bf9ab3c1dada8a13de0e75c8a41c83afccfe91723507eb06c36ee6692f8d
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Advent
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/advent.svg)](https://badge.fury.io/rb/advent)
4
+
3
5
  Have fun with the [Advent of Code](https://rubygems.org) using Ruby.
4
6
 
5
7
  ## Installation
@@ -26,7 +28,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
26
28
 
27
29
  ## Contributing
28
30
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/advent.
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dnlgrv/advent-rb.
30
32
 
31
33
  ## License
32
34
 
@@ -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.0"
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Grieve
@@ -40,8 +40,9 @@ 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
- homepage: https://github.com/dnlgrv/advent
45
+ homepage: https://github.com/dnlgrv/advent-rb
45
46
  licenses:
46
47
  - MIT
47
48
  metadata: {}
@@ -63,5 +64,5 @@ requirements: []
63
64
  rubygems_version: 3.3.7
64
65
  signing_key:
65
66
  specification_version: 4
66
- summary: Have fun with the Advent of Code.
67
+ summary: Have fun with the Advent of Code using Ruby.
67
68
  test_files: []