aoc_generator 0.1.6 → 0.1.7

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: 224ddd170a1b90b1f49ec1b74ae9f866469dfe4613f7e79c74fe21bc7e50df6e
4
- data.tar.gz: ce15c6c8269ce2fbfcbb9a13c435c2ff05f3f87595ab073eec0452fbd261ec4c
3
+ metadata.gz: 4bba636ebf82c12a3532f3b89e1ef4190b6f6c3bd7a44e87ca7c1cc4458c203c
4
+ data.tar.gz: dc0db27bf0088b133e1417bb043bf4df8739ed77b9bad86b84ccb5769dec5b94
5
5
  SHA512:
6
- metadata.gz: 39b6cb3425c18ce2f88628e4d44a603481578e3cdb49096e252c10ff2edc1994c748ba859be5f67c6b6f3360331dd0caf4bbaad608e573939b13f1875fb018fb
7
- data.tar.gz: 29e5215ba788af0c801933c96167f1872bd1c54f722257c9118fa981cd5a9b49b3821cc7f5f64a2bb1592121bd9a2c1cebc2ab651d7a79e0c840d4f409045767
6
+ metadata.gz: 8b377602a3fb8fb57bc3a63652d88ac280e1f879443e19cce3cb5eeb95e69719b8badc3169aedee722f58113d5c3ba1d7180a0b5d578cff941b1d4539c0cc1a3
7
+ data.tar.gz: a6b06f2cb5dce4de4c9e34355fe65e21c16329269e52ba83e1389d5dd4318e2f6a41f68fe02f17aa39467da55dc6c0ead2358b20c95ea33e61054d82ea096089
data/CHANGELOG.md CHANGED
@@ -1,8 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.7] - 2024-12-01
4
+
5
+ - Change README.md to PUZZLE_DESCRIPTION.md
6
+ - Add more setup instructions to the README
7
+ - Allow generator to overwrite PUZZLE_DESCRIPTION.md
8
+ - Don't generate data.txt if there is no session key
9
+
3
10
  ## [0.1.6] - 2024-11-29
4
11
 
5
- - Handle <ul> and <ol> HTML elements
12
+ - Handle HTML list elements
6
13
 
7
14
  ## [0.1.5] - 2024-11-28
8
15
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aoc_generator (0.1.6)
4
+ aoc_generator (0.1.7)
5
5
  fileutils (~> 1.7)
6
6
  nokogiri (~> 1.16)
7
7
  thor (~> 1.3)
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,35 @@ adventofcode/
34
63
  ├── day_01.rb
35
64
  ├── day_01_spec.rb
36
65
  ├── data.txt
37
- └── README.md
66
+ └── PUZZLE_DESCRIPTION.md
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 1
79
+ end
80
+
81
+ def part_two(input)
82
+ # Your solution for part 2
83
+ end
84
+ end
85
+ ```
86
+
87
+ ### `day_XX_spec.rb`
88
+
89
+ ```ruby
90
+ RSpec.describe DayXX do
91
+ # Example test cases from the puzzle
92
+ end
38
93
  ```
94
+
95
+ ## Acknowledgments
96
+
97
+ - 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
- # └── README.md
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
- [readme, data_file, main_file, spec_file].each do |file_data|
34
- next if File.exist?(file_data.path)
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 readme
47
- path = "#{daily_directory}/README.md"
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
@@ -77,7 +83,7 @@ module AdventOfCodeGenerator
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
@@ -108,7 +114,7 @@ module AdventOfCodeGenerator
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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdventOfCodeGenerator
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
 
6
6
  class Error < StandardError; end
7
7
  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.6
4
+ version: 0.1.7
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-28 00:00:00.000000000 Z
11
+ date: 2024-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fileutils