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 +4 -4
- data/README.md +3 -1
- data/lib/advent/cli/solver.rb +10 -15
- data/lib/advent/cli.rb +36 -11
- data/lib/advent/templates/solution.rb.tt +11 -0
- data/lib/advent/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44488f23b0a385b7060d3a2d64d6538dc1e738bbd8600bcc405e1735ace44ff2
|
4
|
+
data.tar.gz: aa26c72769ec2cc0eeb05bf4ed67e3619470e7e1e7e77465c0b19c69b65abe2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8be6f552d4fd5930143da51281cf204b7e93f680358578927094f97dde8443d1d5c4307641286edf14fa2454fde7058abd2a2422afe107d4a857b1bdfdd5129b
|
7
|
+
data.tar.gz: 51575d6fd1d772627c00e199c69f07c4069429787345fa239312effbeac090604c35bf9ab3c1dada8a13de0e75c8a41c83afccfe91723507eb06c36ee6692f8d
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Advent
|
2
2
|
|
3
|
+
[](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/
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dnlgrv/advent-rb.
|
30
32
|
|
31
33
|
## License
|
32
34
|
|
data/lib/advent/cli/solver.rb
CHANGED
@@ -3,31 +3,31 @@
|
|
3
3
|
class Advent::CLI::Solver
|
4
4
|
PARTS = [1, 2]
|
5
5
|
|
6
|
-
def initialize(command,
|
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
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
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,
|
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
|
data/lib/advent/version.rb
CHANGED
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.
|
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: []
|