advent_of_code_generator 1.0.0 → 1.0.1

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: 51f8c6cf08b0d959d77d63605692be3fdc52836a595d104ae2bd300329d9c728
4
- data.tar.gz: 75fac0e3ca5546c6401ff5827a3c7b5d69977421f74c11d68a249f04c8ac5f72
3
+ metadata.gz: 7edb73d2264ff39da5a3eccb4b3cef4766f920bb5f8c27d798585c6ce2e945ed
4
+ data.tar.gz: '059f62d54f1049df523518674d56dcb7db5ab6f96dd5309da149b4a19e203b95'
5
5
  SHA512:
6
- metadata.gz: 29e91e5d1c5807af5eef5866fc016b6bdc841cf6f17184f7c69ce36a96488e8b561826392214189c68e741b2690093f5ba9e6c10a854795024371dbc5cb138b4
7
- data.tar.gz: 9001b4cb32201da0769064005f69bf736d39a99ce57b317e2bf19d3d55f960a0cc87e8896f3a535b4d1f3e2724b6abafc4fc5a72a33952cfbdabb115c6ab4120
6
+ metadata.gz: dffc5cd6a6c0aa711532ce643ede0f5fd8dc2ab0e30773e41244c6e722989fb6f16c212b39b870f2bd91de64af320e4b5b31b08ae1062111e5972e36b1c32065
7
+ data.tar.gz: 4ac450d516794e5bfd80eecaaf4a0e3196f578941e85eb9e69ee82626f0d8c5c43cf2889a4f5fa8118ab25f4a1e98eb05d1ed1c6c661243b5203110930332054
data/README.md CHANGED
@@ -15,7 +15,28 @@ Then run bundle install and your up to go !
15
15
 
16
16
  ## Usage
17
17
 
18
- TODO: Write usage instructions here
18
+ ### Generate
19
+
20
+ For this gem to work, we need to use you Advent of code session cookie in order to fetch your input. You can find
21
+ it in the cookies of https://adventofcode.com/2022/day/DAY/input. Add it to you environment variables as:
22
+
23
+ ```
24
+ export AOC_COOKIE=COOKIE
25
+ ```
26
+
27
+ To generate a day of the current year, run:
28
+
29
+ $ bundle exec aoc generate --day DAY
30
+
31
+ This will create a directory for the day DAY with the ruby file class to solve the puzzle and the input file.
32
+
33
+ ### Solve
34
+
35
+ Incomming command
36
+
37
+ ### Publish
38
+
39
+ Incomming command
19
40
 
20
41
  ## Contributing
21
42
 
@@ -6,28 +6,28 @@ module AdventOfCodeGenerator
6
6
  class GenerateDay < Thor::Group
7
7
  include Thor::Actions
8
8
 
9
- class_option :day
10
- class_option :year
9
+ class_option :day, :type => :numeric
10
+ class_option :year, :type => :numeric
11
11
 
12
12
  def self.source_root
13
13
  File.dirname(__FILE__)
14
14
  end
15
15
 
16
16
  def create_day_directory
17
- unless Dir.exist?(day)
17
+ unless Dir.exist?(day_name)
18
18
  say "Creating day #{day} directory", :green
19
- Dir.mkdir(day)
19
+ Dir.mkdir(day_name)
20
20
  end
21
21
  end
22
22
 
23
23
  def create_solution_file
24
24
  say "Creating day #{day} solution file", :green
25
- template('templates/empty_day.tt', "#{day}/#{day}.rb")
25
+ template('templates/empty_day.tt', "#{day_name}/day#{day_name}.rb")
26
26
  end
27
27
 
28
28
  def create_input_file
29
29
  say "Creating day #{day} input file", :green
30
- create_file "#{day}/input.txt", fetch_input
30
+ create_file "#{day_name}/input.txt", fetch_input
31
31
  end
32
32
 
33
33
  def prints_done
@@ -37,8 +37,9 @@ module AdventOfCodeGenerator
37
37
  private
38
38
 
39
39
  def fetch_input
40
+ binding.pry
40
41
  RestClient.get(
41
- "https://adventofcode.com/#{year}/day/#{day.to_i}/input",
42
+ "https://adventofcode.com/#{year}/day/#{day}/input",
42
43
  cookies: { session: ENV.fetch('AOC_COOKIE', '') },
43
44
  'User-Agent' => "github.com/Tyflomate/advent_of_code_generator by florian@tymate.com"
44
45
  ).body
@@ -47,11 +48,17 @@ module AdventOfCodeGenerator
47
48
  end
48
49
 
49
50
  def day
50
- options[:day]
51
+ @day ||= options[:day]
52
+ end
53
+
54
+ def day_name
55
+ return day.to_s if day > 9
56
+
57
+ "0#{day}"
51
58
  end
52
59
 
53
60
  def year
54
- options[:year]
61
+ @year ||= options[:year]
55
62
  end
56
63
  end
57
64
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Day<%= day %>
3
+ class Day<%= day_name %>
4
4
  def initialize
5
- @input = File.readlines('./<%= day %>/input.txt')
5
+ @input = File.readlines('./<%= day_name %>/input.txt')
6
6
  end
7
7
 
8
8
  def part1
@@ -3,7 +3,7 @@
3
3
  module AdventOfCodeGenerator
4
4
  module Parser
5
5
  def parse_day(day)
6
- return day_to_string(day) if day > 0 && day < 26
6
+ return day if day > 0 && day < 26
7
7
 
8
8
  raise InvalidDayError
9
9
  end
@@ -15,13 +15,5 @@ module AdventOfCodeGenerator
15
15
 
16
16
  raise InvalidYearError
17
17
  end
18
-
19
- private
20
-
21
- def day_to_string(day)
22
- return day.to_s if day > 9
23
-
24
- "0#{day}"
25
- end
26
18
  end
27
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdventOfCode
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
@@ -21,7 +21,7 @@ module AdventOfCodeGenerator
21
21
  day = parse_day(options[:day])
22
22
  year = parse_year(options[:year])
23
23
 
24
- invoke 'generateDay', :day => day, :year => year
24
+ invoke 'generateDay', [], :day => day, :year => year
25
25
  rescue AdventOfCodeGenerator::Error => e
26
26
  say e.message, :red
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advent_of_code_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Lecointe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-02 00:00:00.000000000 Z
11
+ date: 2022-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor