aoc_generator 0.1.5 → 0.1.7

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: 1ae6b1d2734c4a21d5608955e4bc5c36d6a2226644834eebbade401de59ebe87
4
- data.tar.gz: fc64a51413098fc34a5b33a5ab7d6df042bef03800a134b9ab06c3c950e289d4
3
+ metadata.gz: 4bba636ebf82c12a3532f3b89e1ef4190b6f6c3bd7a44e87ca7c1cc4458c203c
4
+ data.tar.gz: dc0db27bf0088b133e1417bb043bf4df8739ed77b9bad86b84ccb5769dec5b94
5
5
  SHA512:
6
- metadata.gz: a6165ed4974b4f84a8500530ca257e757bf61ccb932233e8d34e7237ab36f5e0208bc89b592e09844252e86b4253659197d5322799ff184224ab292c97d93c0a
7
- data.tar.gz: 44620d63c9fcf49970148ae4ae4335bc1e9d97a942c33310df4a0dc860c353322ad229981dbbb9f6bcba2e0e7de7a2ac904d32ca283ba9ef45e45ae3c968a7b6
6
+ metadata.gz: 8b377602a3fb8fb57bc3a63652d88ac280e1f879443e19cce3cb5eeb95e69719b8badc3169aedee722f58113d5c3ba1d7180a0b5d578cff941b1d4539c0cc1a3
7
+ data.tar.gz: a6b06f2cb5dce4de4c9e34355fe65e21c16329269e52ba83e1389d5dd4318e2f6a41f68fe02f17aa39467da55dc6c0ead2358b20c95ea33e61054d82ea096089
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
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
+
10
+ ## [0.1.6] - 2024-11-29
11
+
12
+ - Handle HTML list elements
13
+
3
14
  ## [0.1.5] - 2024-11-28
4
15
 
5
16
  - Generate main file with class methods, rather than instance methods
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aoc_generator (0.1.5)
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
@@ -49,15 +49,20 @@ module AdventOfCodeGenerator
49
49
 
50
50
  def process_node(node)
51
51
  case node.name
52
- when "h2"
53
- "## #{node.text}\n"
54
- when "p"
55
- "#{process_paragraph(node)}\n"
56
- when "pre"
57
- "```sh\n#{node.text.strip}\n```\n"
52
+ when "h2" then "## #{node.text}\n"
53
+ when "ul" then "#{process_list(node, "-")}\n"
54
+ when "ol" then"#{process_list(node, "1.")}\n"
55
+ when "p" then "#{process_paragraph(node)}\n"
56
+ when "pre" then "```sh\n#{node.text.strip}\n```\n"
58
57
  end
59
58
  end
60
59
 
60
+ def process_list(list_node, marker)
61
+ list_node.css("li").map do |item|
62
+ "#{marker} #{process_paragraph(item)}"
63
+ end.join("\n")
64
+ end
65
+
61
66
  def process_paragraph(para)
62
67
  para.inner_html
63
68
  .gsub(%r{<a[^>]*href="([^"]*)"[^>]*>(.*?)</a>}, '[\2](\1)')
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdventOfCodeGenerator
4
- VERSION = "0.1.5"
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.5
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