advent_of_code_generator 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +13 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +21 -0
- data/README.md +22 -0
- data/Rakefile +8 -0
- data/exe/aoc +6 -0
- data/lib/advent_of_code_generator/generate_day.rb +57 -0
- data/lib/advent_of_code_generator/templates/empty_day.tt +15 -0
- data/lib/advent_of_code_generator/utils/error.rb +20 -0
- data/lib/advent_of_code_generator/utils/parser.rb +27 -0
- data/lib/advent_of_code_generator/utils/version.rb +5 -0
- data/lib/advent_of_code_generator/utils.rb +5 -0
- data/lib/advent_of_code_generator.rb +31 -3
- metadata +39 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51f8c6cf08b0d959d77d63605692be3fdc52836a595d104ae2bd300329d9c728
|
4
|
+
data.tar.gz: 75fac0e3ca5546c6401ff5827a3c7b5d69977421f74c11d68a249f04c8ac5f72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29e91e5d1c5807af5eef5866fc016b6bdc841cf6f17184f7c69ce36a96488e8b561826392214189c68e741b2690093f5ba9e6c10a854795024371dbc5cb138b4
|
7
|
+
data.tar.gz: 9001b4cb32201da0769064005f69bf736d39a99ce57b317e2bf19d3d55f960a0cc87e8896f3a535b4d1f3e2724b6abafc4fc5a72a33952cfbdabb115c6ab4120
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in advent_of_code_generator.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
gem "rubocop", "~> 1.21"
|
10
|
+
gem 'thor', '~> 1.2', '>= 1.2.1'
|
11
|
+
gem "pry"
|
12
|
+
gem 'rest-client', '~> 2.1'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
advent_of_code_generator (0.1.0)
|
5
|
+
thor (~> 1.2, >= 1.2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
coderay (1.1.3)
|
12
|
+
domain_name (0.5.20190701)
|
13
|
+
unf (>= 0.0.5, < 1.0.0)
|
14
|
+
http-accept (1.7.0)
|
15
|
+
http-cookie (1.0.5)
|
16
|
+
domain_name (~> 0.5)
|
17
|
+
json (2.6.2)
|
18
|
+
method_source (1.0.0)
|
19
|
+
mime-types (3.4.1)
|
20
|
+
mime-types-data (~> 3.2015)
|
21
|
+
mime-types-data (3.2022.0105)
|
22
|
+
netrc (0.11.0)
|
23
|
+
parallel (1.22.1)
|
24
|
+
parser (3.1.3.0)
|
25
|
+
ast (~> 2.4.1)
|
26
|
+
pry (0.14.1)
|
27
|
+
coderay (~> 1.1)
|
28
|
+
method_source (~> 1.0)
|
29
|
+
rainbow (3.1.1)
|
30
|
+
rake (13.0.6)
|
31
|
+
regexp_parser (2.6.1)
|
32
|
+
rest-client (2.1.0)
|
33
|
+
http-accept (>= 1.7.0, < 2.0)
|
34
|
+
http-cookie (>= 1.0.2, < 2.0)
|
35
|
+
mime-types (>= 1.16, < 4.0)
|
36
|
+
netrc (~> 0.8)
|
37
|
+
rexml (3.2.5)
|
38
|
+
rubocop (1.39.0)
|
39
|
+
json (~> 2.3)
|
40
|
+
parallel (~> 1.10)
|
41
|
+
parser (>= 3.1.2.1)
|
42
|
+
rainbow (>= 2.2.2, < 4.0)
|
43
|
+
regexp_parser (>= 1.8, < 3.0)
|
44
|
+
rexml (>= 3.2.5, < 4.0)
|
45
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
46
|
+
ruby-progressbar (~> 1.7)
|
47
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
48
|
+
rubocop-ast (1.24.0)
|
49
|
+
parser (>= 3.1.1.0)
|
50
|
+
ruby-progressbar (1.11.0)
|
51
|
+
thor (1.2.1)
|
52
|
+
unf (0.1.4)
|
53
|
+
unf_ext
|
54
|
+
unf_ext (0.0.8.2)
|
55
|
+
unicode-display_width (2.3.0)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
x86_64-linux
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
advent_of_code_generator!
|
62
|
+
pry
|
63
|
+
rake (~> 13.0)
|
64
|
+
rest-client (~> 2.1)
|
65
|
+
rubocop (~> 1.21)
|
66
|
+
thor (~> 1.2, >= 1.2.1)
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
2.3.18
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Tyflomate
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# AdventOfCodeGenerator
|
2
|
+
|
3
|
+
A custom gem that allows you to generate the necessary files to solve [Advent of Code](https://advent-of-code.com) days in Ruby !
|
4
|
+
|
5
|
+
This project is based on [advent_of_code_cli](https://github.com/egiurleo/advent_of_code_cli). Pretty much the same
|
6
|
+
usage but I wanted to make my own because why not ! Go check it out 👌
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
You can add this line to your Gemfile:
|
11
|
+
|
12
|
+
$ gem "advent_of_code_generator"
|
13
|
+
|
14
|
+
Then run bundle install and your up to go !
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
TODO: Write usage instructions here
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
Bug reports and pull requests are welcome on this GitHub repository.
|
data/Rakefile
ADDED
data/exe/aoc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rest-client'
|
4
|
+
|
5
|
+
module AdventOfCodeGenerator
|
6
|
+
class GenerateDay < Thor::Group
|
7
|
+
include Thor::Actions
|
8
|
+
|
9
|
+
class_option :day
|
10
|
+
class_option :year
|
11
|
+
|
12
|
+
def self.source_root
|
13
|
+
File.dirname(__FILE__)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_day_directory
|
17
|
+
unless Dir.exist?(day)
|
18
|
+
say "Creating day #{day} directory", :green
|
19
|
+
Dir.mkdir(day)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_solution_file
|
24
|
+
say "Creating day #{day} solution file", :green
|
25
|
+
template('templates/empty_day.tt', "#{day}/#{day}.rb")
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_input_file
|
29
|
+
say "Creating day #{day} input file", :green
|
30
|
+
create_file "#{day}/input.txt", fetch_input
|
31
|
+
end
|
32
|
+
|
33
|
+
def prints_done
|
34
|
+
say 'Generation done, enjoy !', :blue
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def fetch_input
|
40
|
+
RestClient.get(
|
41
|
+
"https://adventofcode.com/#{year}/day/#{day.to_i}/input",
|
42
|
+
cookies: { session: ENV.fetch('AOC_COOKIE', '') },
|
43
|
+
'User-Agent' => "github.com/Tyflomate/advent_of_code_generator by florian@tymate.com"
|
44
|
+
).body
|
45
|
+
rescue RestClient::BadRequest, RestClient::ExceptionWithResponse => e
|
46
|
+
e.response
|
47
|
+
end
|
48
|
+
|
49
|
+
def day
|
50
|
+
options[:day]
|
51
|
+
end
|
52
|
+
|
53
|
+
def year
|
54
|
+
options[:year]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module AdventOfCodeGenerator
|
3
|
+
class Error < StandardError
|
4
|
+
def message
|
5
|
+
raise NotImplementedError
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class InvalidDayError < Error
|
10
|
+
def message
|
11
|
+
"Please use an integer between 1 and 25 as day argument."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class InvalidYearError < Error
|
16
|
+
def message
|
17
|
+
"Please insert a valid year between the first iteration of 2015 and current year."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AdventOfCodeGenerator
|
4
|
+
module Parser
|
5
|
+
def parse_day(day)
|
6
|
+
return day_to_string(day) if day > 0 && day < 26
|
7
|
+
|
8
|
+
raise InvalidDayError
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_year(year)
|
12
|
+
current_year = Time.now.year
|
13
|
+
return current_year unless year
|
14
|
+
return year if year <= current_year && year > 2014
|
15
|
+
|
16
|
+
raise InvalidYearError
|
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
|
+
end
|
27
|
+
end
|
@@ -1,7 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require "thor"
|
4
|
+
require "pry"
|
5
|
+
require_relative "advent_of_code_generator/utils"
|
6
|
+
require_relative "advent_of_code_generator/generate_day"
|
7
|
+
|
8
|
+
module AdventOfCodeGenerator
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class App < Thor
|
12
|
+
include Thor::Actions
|
13
|
+
include AdventOfCodeGenerator::Parser
|
14
|
+
|
15
|
+
map "-g" => :generate
|
16
|
+
|
17
|
+
option :day, :type => :numeric, :required => true, :aliases => "-d"
|
18
|
+
option :year, :type => :numeric, :aliases => "-y"
|
19
|
+
desc "generate", "generate files for a day"
|
20
|
+
def generate
|
21
|
+
day = parse_day(options[:day])
|
22
|
+
year = parse_year(options[:year])
|
23
|
+
|
24
|
+
invoke 'generateDay', :day => day, :year => year
|
25
|
+
rescue AdventOfCodeGenerator::Error => e
|
26
|
+
say e.message, :red
|
27
|
+
end
|
28
|
+
|
29
|
+
register(AdventOfCodeGenerator::GenerateDay, "generateDay", "generateDay", "Generate days files")
|
30
|
+
|
31
|
+
def self.exit_on_failure?
|
32
|
+
true
|
33
|
+
end
|
6
34
|
end
|
7
35
|
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:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Lecointe
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '1.2'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.2.
|
22
|
+
version: 1.2.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,18 +29,48 @@ dependencies:
|
|
29
29
|
version: '1.2'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.2.
|
32
|
+
version: 1.2.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rest-client
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.1'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.1'
|
33
47
|
description: Generate input and startup class for advent of code days
|
34
48
|
email: florian@tymate.com
|
35
|
-
executables:
|
49
|
+
executables:
|
50
|
+
- aoc
|
36
51
|
extensions: []
|
37
52
|
extra_rdoc_files: []
|
38
53
|
files:
|
54
|
+
- ".rubocop.yml"
|
55
|
+
- Gemfile
|
56
|
+
- Gemfile.lock
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- exe/aoc
|
39
61
|
- lib/advent_of_code_generator.rb
|
40
|
-
|
62
|
+
- lib/advent_of_code_generator/generate_day.rb
|
63
|
+
- lib/advent_of_code_generator/templates/empty_day.tt
|
64
|
+
- lib/advent_of_code_generator/utils.rb
|
65
|
+
- lib/advent_of_code_generator/utils/error.rb
|
66
|
+
- lib/advent_of_code_generator/utils/parser.rb
|
67
|
+
- lib/advent_of_code_generator/utils/version.rb
|
68
|
+
homepage: https://github.com/Tyflomate/advent_of_code_generator
|
41
69
|
licenses:
|
42
70
|
- MIT
|
43
|
-
metadata:
|
71
|
+
metadata:
|
72
|
+
homepage_uri: https://github.com/Tyflomate/advent_of_code_generator
|
73
|
+
source_code_uri: https://github.com/Tyflomate/advent_of_code_generator
|
44
74
|
post_install_message:
|
45
75
|
rdoc_options: []
|
46
76
|
require_paths:
|
@@ -49,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
79
|
requirements:
|
50
80
|
- - ">="
|
51
81
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
82
|
+
version: 2.6.0
|
53
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
84
|
requirements:
|
55
85
|
- - ">="
|