aoc_generator 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/Gemfile.lock +1 -1
- data/README.md +84 -2
- data/lib/advent_of_code_generator/generator.rb +26 -20
- data/lib/advent_of_code_generator.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53517b89d8f104b0cd5924d2f09eeb6607f735131b80b7b0d6dd694da1b0a842
|
4
|
+
data.tar.gz: cd46560f3dbd64457b37b5459bf13937474c41b97120b84ab0a2c57a36385579
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da3ec592eff238f75cd44853cdf7699f6ad4838a2b51796067f5e514743de03289a82201557d167ad7012958e8cb0715520d0e2fb090094ad0796a9662bb65bf
|
7
|
+
data.tar.gz: cc84976227d250848e62b1025ff3b4bb00ea474047e64f105144bbe2311b2fe3cbfa1e52ffca75e7db0c58f8f269e01d02686a340c00d38c4c72c75d6fbda967
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.1.8] - 2024-12-02
|
4
|
+
|
5
|
+
- Use commented-out code in templates
|
6
|
+
|
7
|
+
## [0.1.7] - 2024-12-01
|
8
|
+
|
9
|
+
- Change README.md to PUZZLE_DESCRIPTION.md
|
10
|
+
- Add more setup instructions to the README
|
11
|
+
- Allow generator to overwrite PUZZLE_DESCRIPTION.md
|
12
|
+
- Don't generate data.txt if there is no session key
|
13
|
+
|
3
14
|
## [0.1.6] - 2024-11-29
|
4
15
|
|
5
|
-
- Handle
|
16
|
+
- Handle HTML list elements
|
6
17
|
|
7
18
|
## [0.1.5] - 2024-11-28
|
8
19
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,35 @@
|
|
1
1
|
# Advent of Code Generator
|
2
2
|
|
3
|
-
A Ruby gem that generates daily puzzle templates for Advent of Code.
|
3
|
+
A Ruby gem that generates daily puzzle templates for Advent of Code with automatically scraped puzzle descriptions and input data.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```sh
|
8
|
+
gem install advent_of_code_generator
|
9
|
+
```
|
10
|
+
|
11
|
+
### Prerequisites
|
12
|
+
|
13
|
+
- RSpec: This gem uses RSpec for testing. If you haven't installed it yet, run:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
gem install rspec
|
17
|
+
```
|
18
|
+
|
19
|
+
- Or optionally, set it up as you would for a normal Ruby project by adding `rspec` to your `Gemfile` and running `bundle install`.
|
20
|
+
|
21
|
+
### Setting up your session key
|
22
|
+
|
23
|
+
1. Log in to [Advent of Code](https://adventofcode.com)
|
24
|
+
2. In your browser's developer tools, find the `session` cookie value
|
25
|
+
- Chrome: DevTools (F12) > Application > Cookies > adventofcode.com
|
26
|
+
- Firefox: DevTools (F12) > Storage > Cookies
|
27
|
+
3. Store the session key in your environment:
|
28
|
+
|
29
|
+
```sh
|
30
|
+
# Add to your ~/.bashrc, ~/.zshrc, or equivalent
|
31
|
+
export AOC_SESSION='your_session_key_here'
|
32
|
+
```
|
4
33
|
|
5
34
|
## Usage
|
6
35
|
|
@@ -34,5 +63,58 @@ adventofcode/
|
|
34
63
|
├── day_01.rb
|
35
64
|
├── day_01_spec.rb
|
36
65
|
├── data.txt
|
37
|
-
└──
|
66
|
+
└── PUZZLE_DESCRIPTION.md
|
38
67
|
```
|
68
|
+
|
69
|
+
## Generated File Contents
|
70
|
+
|
71
|
+
The generator creates the following files with basic templates:
|
72
|
+
|
73
|
+
### `day_XX.rb`
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
class DayXX
|
77
|
+
def part_one(input)
|
78
|
+
# Your solution for Part One
|
79
|
+
end
|
80
|
+
|
81
|
+
def part_two(input)
|
82
|
+
# Your solution for Part Two
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
### `day_XX_spec.rb`
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
RSpec.describe Cheddachedda::YearXXXX::DayXX do
|
91
|
+
it "solves Part One" do
|
92
|
+
input = <<~INPUT
|
93
|
+
1abc2
|
94
|
+
pqr3stu8vwx
|
95
|
+
a1b2c3d4e5f
|
96
|
+
treb7uchet
|
97
|
+
INPUT
|
98
|
+
|
99
|
+
expect(described_class.part_one(input)).to eq(142)
|
100
|
+
end
|
101
|
+
|
102
|
+
# it "solves Part Two" do
|
103
|
+
# input = <<~INPUT
|
104
|
+
# two1nine
|
105
|
+
# eightwothree
|
106
|
+
# abcone2threexyz
|
107
|
+
# xtwone3four
|
108
|
+
# 4nineeightseven2
|
109
|
+
# zoneight234
|
110
|
+
# 7pqrstsixteen
|
111
|
+
# INPUT
|
112
|
+
|
113
|
+
# expect(described_class.part_two(input)).to eq(281)
|
114
|
+
# end
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
## Acknowledgments
|
119
|
+
|
120
|
+
- Thanks to [Eric Wastl](https://twitter.com/ericwastl) for creating [Advent of Code](https://adventofcode.com)
|
@@ -15,25 +15,24 @@ module AdventOfCodeGenerator
|
|
15
15
|
# ├── day_01.rb
|
16
16
|
# ├── day_01_spec.rb
|
17
17
|
# ├── data.txt
|
18
|
-
# └──
|
18
|
+
# └── PUZZLE_DESCRIPTION.md
|
19
19
|
#
|
20
20
|
class Generator
|
21
|
-
FileData = Struct.new(:path, :content)
|
21
|
+
FileData = Struct.new(:path, :content, :require_session, :allow_overwrite)
|
22
22
|
|
23
23
|
def initialize(options, scraped_data)
|
24
24
|
@year = options[:year].to_s
|
25
25
|
@day = options[:day].to_s.rjust(2, "0") # Ensures day is two digits (e.g., "01" instead of "1")
|
26
26
|
@username = options[:username].gsub(/[_\-\.\s]/, "")
|
27
|
+
@session = options[:session]
|
27
28
|
@scraped_data = scraped_data
|
28
29
|
end
|
29
30
|
|
30
31
|
def call
|
31
32
|
FileUtils.mkdir_p(daily_directory)
|
32
33
|
|
33
|
-
[
|
34
|
-
|
35
|
-
|
36
|
-
File.write(file_data.path, file_data.content)
|
34
|
+
[puzzle_description, data_file, main_file, spec_file].each do |file_data|
|
35
|
+
generate_file(file_data)
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
@@ -43,18 +42,25 @@ module AdventOfCodeGenerator
|
|
43
42
|
@daily_directory ||= "#{@username}/year_#{@year}/day_#{@day}"
|
44
43
|
end
|
45
44
|
|
46
|
-
def
|
47
|
-
|
45
|
+
def generate_file(file_data)
|
46
|
+
return if file_data.require_session && @session.nil?
|
47
|
+
return if File.exist?(file_data.path) && !file_data.allow_overwrite
|
48
|
+
|
49
|
+
File.write(file_data.path, file_data.content)
|
50
|
+
end
|
51
|
+
|
52
|
+
def puzzle_description
|
53
|
+
path = "#{daily_directory}/PUZZLE_DESCRIPTION.md"
|
48
54
|
content = @scraped_data[:puzzle_description]
|
49
55
|
|
50
|
-
FileData.new(path, content)
|
56
|
+
FileData.new(path, content, false, true)
|
51
57
|
end
|
52
58
|
|
53
59
|
def data_file
|
54
60
|
path = "#{daily_directory}/data.txt"
|
55
61
|
content = @scraped_data[:input_data]
|
56
62
|
|
57
|
-
FileData.new(path, content)
|
63
|
+
FileData.new(path, content, true, false)
|
58
64
|
end
|
59
65
|
|
60
66
|
def main_file
|
@@ -66,18 +72,18 @@ module AdventOfCodeGenerator
|
|
66
72
|
module Year#{@year}
|
67
73
|
class Day#{@day}
|
68
74
|
def self.part_one(input)
|
69
|
-
|
75
|
+
# Your solution for Part One
|
70
76
|
end
|
71
77
|
|
72
78
|
def self.part_two(input)
|
73
|
-
|
79
|
+
# Your solution for Part Two
|
74
80
|
end
|
75
81
|
end
|
76
82
|
end
|
77
83
|
end
|
78
84
|
RUBY
|
79
85
|
|
80
|
-
FileData.new(path, content)
|
86
|
+
FileData.new(path, content, false, false)
|
81
87
|
end
|
82
88
|
|
83
89
|
def spec_file
|
@@ -98,17 +104,17 @@ module AdventOfCodeGenerator
|
|
98
104
|
expect(described_class.part_one(input)).to eq(#{expectations[0]})
|
99
105
|
end
|
100
106
|
|
101
|
-
it "solves Part Two"
|
102
|
-
|
103
|
-
|
104
|
-
|
107
|
+
# it "solves Part Two" do
|
108
|
+
# input = <<~INPUT
|
109
|
+
# #{input[1]&.gsub("\n", "\n # ")}
|
110
|
+
# INPUT
|
105
111
|
|
106
|
-
|
107
|
-
end
|
112
|
+
# expect(described_class.part_two(input)).to eq(#{expectations[1]})
|
113
|
+
# end
|
108
114
|
end
|
109
115
|
RUBY
|
110
116
|
|
111
|
-
FileData.new(path, content)
|
117
|
+
FileData.new(path, content, false, false)
|
112
118
|
end
|
113
119
|
end
|
114
120
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aoc_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fileutils
|