acclir 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d4139f62076d4afe47b9dd261691960c5255efe927838d5b423a8d0158889833
4
+ data.tar.gz: dbefe015f4cd1746cc662ecb8dfa10482ef5d029566e38ad4b7bc029b09411c5
5
+ SHA512:
6
+ metadata.gz: 936f48f2c0780bb1dc891781acf4cfdd3bb9a9010f01e7a5125f36e26dae1d9b87660ba77f7f74e5216efe42c61f47e161d1630564a4d52014a53e54f58e5baa
7
+ data.tar.gz: e4c03005f957b6a00679c2f1524d6061773b803d8c5a0968d2ebbf930def4bdecfa77a4e4eed12dd1c0a9ef93fdc4149ecb6298025db61893a1362495b0721f2
data/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ [*]
7
+ indent_style = space
8
+ indent_size = 2
9
+ end_of_line = lf
10
+ charset = utf-8
11
+ trim_trailing_whitespace = false
12
+ insert_final_newline = false
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - "spec/**/*"
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-12-28
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in acclir.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+ gem "webmock"
12
+
13
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ acclir (0.1.0)
5
+ minitest
6
+ nokogiri (~> 1.13.10)
7
+ thor (~> 1.2.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.8.1)
13
+ public_suffix (>= 2.0.2, < 6.0)
14
+ ast (2.4.2)
15
+ crack (0.4.5)
16
+ rexml
17
+ diff-lcs (1.5.0)
18
+ hashdiff (1.0.1)
19
+ json (2.6.3)
20
+ mini_portile2 (2.8.1)
21
+ minitest (5.17.0)
22
+ nokogiri (1.13.10)
23
+ mini_portile2 (~> 2.8.0)
24
+ racc (~> 1.4)
25
+ nokogiri (1.13.10-arm64-darwin)
26
+ racc (~> 1.4)
27
+ nokogiri (1.13.10-x86_64-linux)
28
+ racc (~> 1.4)
29
+ parallel (1.22.1)
30
+ parser (3.1.3.0)
31
+ ast (~> 2.4.1)
32
+ public_suffix (5.0.1)
33
+ racc (1.6.2)
34
+ rainbow (3.1.1)
35
+ rake (13.0.6)
36
+ regexp_parser (2.6.1)
37
+ rexml (3.2.5)
38
+ rspec (3.12.0)
39
+ rspec-core (~> 3.12.0)
40
+ rspec-expectations (~> 3.12.0)
41
+ rspec-mocks (~> 3.12.0)
42
+ rspec-core (3.12.0)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-expectations (3.12.1)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.12.0)
47
+ rspec-mocks (3.12.1)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.12.0)
50
+ rspec-support (3.12.0)
51
+ rubocop (1.40.0)
52
+ json (~> 2.3)
53
+ parallel (~> 1.10)
54
+ parser (>= 3.1.2.1)
55
+ rainbow (>= 2.2.2, < 4.0)
56
+ regexp_parser (>= 1.8, < 3.0)
57
+ rexml (>= 3.2.5, < 4.0)
58
+ rubocop-ast (>= 1.23.0, < 2.0)
59
+ ruby-progressbar (~> 1.7)
60
+ unicode-display_width (>= 1.4.0, < 3.0)
61
+ rubocop-ast (1.24.0)
62
+ parser (>= 3.1.1.0)
63
+ ruby-progressbar (1.11.0)
64
+ thor (1.2.1)
65
+ unicode-display_width (2.3.0)
66
+ webmock (3.18.1)
67
+ addressable (>= 2.8.0)
68
+ crack (>= 0.3.2)
69
+ hashdiff (>= 0.4.0, < 2.0.0)
70
+
71
+ PLATFORMS
72
+ arm64-darwin-22
73
+ ruby
74
+ x86_64-linux
75
+
76
+ DEPENDENCIES
77
+ acclir!
78
+ rake (~> 13.0)
79
+ rspec (~> 3.0)
80
+ rubocop (~> 1.21)
81
+ webmock
82
+
83
+ BUNDLED WITH
84
+ 2.4.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Tsubasa Kusaka
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Acclir
2
+
3
+ AtCoder CLI developed in Ruby.
4
+
5
+ ## Installation
6
+
7
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/acclir.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/acclir.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/acclir/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "acclir"
7
+ spec.version = Acclir::VERSION
8
+ spec.authors = ["n0h0"]
9
+ spec.email = ["kusakatsubasa@gmail.com"]
10
+
11
+ spec.summary = "AtCoder CLI developed in Ruby."
12
+ spec.homepage = "https://github.com/n0h0/acclir"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/n0h0/acclir"
18
+ spec.metadata["changelog_uri"] = "https://github.com/n0h0/acclir/blob/main/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "minitest"
32
+ spec.add_dependency "nokogiri", "~> 1.13.10"
33
+ spec.add_dependency "thor", "~> 1.2.1"
34
+
35
+ # For more information and examples about making a new gem, check out our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
data/exe/acclir ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/acclir"
5
+
6
+ Acclir::CLI.start(ARGV)
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open-uri"
4
+
5
+ module Acclir
6
+ module AtCoder
7
+ # AtCoder contest
8
+ class Contest
9
+ attr_reader :id
10
+
11
+ def initialize(id)
12
+ @id = id
13
+ end
14
+
15
+ def tasks
16
+ @tasks ||= extract_task_ids.map { |task_id| Task.new(id, task_id) }
17
+ end
18
+
19
+ private
20
+
21
+ def url
22
+ @url ||= ATCODER_TASKS_URL_PROC.call(id)
23
+ end
24
+
25
+ def document
26
+ @document ||= Nokogiri::HTML(URI.parse(url).open)
27
+ end
28
+
29
+ def extract_task_ids
30
+ hrefs = document.xpath("//a[@href]").map do |element|
31
+ element.attribute("href").content
32
+ end
33
+
34
+ hrefs.uniq.map { |href| href.match(ATCODER_TASK_PATH_REGEX_PROC.call(id))&.[](:task) }.compact
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acclir
4
+ module AtCoder
5
+ # Example problem input and output
6
+ class Sample
7
+ attr_reader :input, :output
8
+
9
+ def initialize(input, output)
10
+ @input = input
11
+ @output = output
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open-uri"
4
+ require "nokogiri"
5
+
6
+ module Acclir
7
+ module AtCoder
8
+ # AtCoder problem
9
+ class Task
10
+ SAMPLE_INPUT_TITLE = "Sample Input"
11
+ SAMPLE_OUTPUT_TITLE = "Sample Output"
12
+
13
+ attr_reader :contest_id, :id
14
+
15
+ def initialize(contest_id, id)
16
+ @contest_id = contest_id
17
+ @id = id
18
+ end
19
+
20
+ def samples
21
+ @samples ||= extract_samples.map { |input, output| Sample.new(input, output) }
22
+ end
23
+
24
+ private
25
+
26
+ def url
27
+ @url ||= ATCODER_TASK_URL_PROC.call(contest_id, id)
28
+ end
29
+
30
+ def document
31
+ @document ||= Nokogiri::HTML(URI.parse(url).open)
32
+ end
33
+
34
+ def extract_samples
35
+ extract_sample_inputs.zip(extract_sample_outputs)
36
+ end
37
+
38
+ def extract_sample_inputs
39
+ document.xpath("//*[@id='task-statement']//section").each_with_object([]) do |element, sample_inputs|
40
+ sample_inputs << element.at("./pre").content if element.at("./h3").content.start_with?(SAMPLE_INPUT_TITLE)
41
+ end
42
+ end
43
+
44
+ def extract_sample_outputs
45
+ document.xpath("//*[@id='task-statement']//section").each_with_object([]) do |element, sample_outputs|
46
+ sample_outputs << element.at("./pre").content if element.at("./h3").content.start_with?(SAMPLE_OUTPUT_TITLE)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./at_coder/contest"
4
+ require_relative "./at_coder/sample"
5
+ require_relative "./at_coder/task"
6
+
7
+ module Acclir
8
+ module AtCoder
9
+ ATCODER_URL = "https://atcoder.jp"
10
+
11
+ ATCODER_TASKS_PATH_PROC = ->(contest_id) { "/contests/#{contest_id}/tasks" }
12
+ ATCODER_TASKS_URL_PROC = ->(contest_id) { "#{ATCODER_URL}/contests/#{contest_id}/tasks" }
13
+
14
+ ATCODER_TASK_PATH_REGEX_PROC = ->(contest_id) { %r{^/contests/#{contest_id}/tasks/(?<task>\w+)$} }
15
+ ATCODER_TASK_URL_PROC = ->(contest_id, task_id) { "#{ATCODER_URL}/contests/#{contest_id}/tasks/#{task_id}" }
16
+ end
17
+ end
data/lib/acclir/cli.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ require_relative "./command/new"
6
+
7
+ module Acclir
8
+ # Acclir CLI
9
+ class CLI < Thor
10
+ package_name "Acclir"
11
+
12
+ def self.exit_on_failure?
13
+ true
14
+ end
15
+
16
+ register(Command::New, "new", "new CONTEST_ID", "Generate files for the contest")
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acclir
4
+ module Command
5
+ # Generate files for the contest
6
+ class New < Thor::Group
7
+ include Thor::Actions
8
+
9
+ BASE_NAME = "main"
10
+
11
+ argument :contest_id
12
+
13
+ attr_accessor :contest, :config
14
+
15
+ def self.source_root
16
+ File.dirname(__FILE__)
17
+ end
18
+
19
+ def prepare
20
+ self.contest = AtCoder::Contest.new(contest_id)
21
+ end
22
+
23
+ def create_contest_files
24
+ contest.tasks.each do |task|
25
+ dir = "#{contest.id}/#{task.id}/"
26
+ file_path = "./#{dir}/#{BASE_NAME}.rb"
27
+ test_file_path = "./#{dir}/#{BASE_NAME}_test.rb"
28
+
29
+ create_file file_path
30
+
31
+ template(
32
+ "../templates/new/#{BASE_NAME}_test.rb.tt", test_file_path,
33
+ { file_path: file_path, task: task }
34
+ )
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minitest/autorun"
4
+ require "stringio"
5
+
6
+ # <%= config[:task].id %>
7
+ class MainTest < Minitest::Test
8
+ <% config[:task].samples.each.with_index(1) do |sample, index| %>
9
+ def test_sample<%= index %>
10
+ $stdin = StringIO.new(<<-STDIN)
11
+ <%= sample.input.chomp %>
12
+ STDIN
13
+
14
+ assert_output(<<~STDOUT) { load "<%= config[:file_path] %>" }
15
+ <%= sample.output.chomp %>
16
+ STDOUT
17
+ end
18
+ <% end %>
19
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acclir
4
+ VERSION = "0.1.0"
5
+ end
data/lib/acclir.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "acclir/at_coder"
4
+ require_relative "acclir/cli"
5
+ require_relative "acclir/version"
6
+
7
+ # :nodoc:
8
+ module Acclir
9
+ end
data/sig/acclir.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Acclir
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acclir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - n0h0
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.13.10
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.13.10
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.1
55
+ description:
56
+ email:
57
+ - kusakatsubasa@gmail.com
58
+ executables:
59
+ - acclir
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".editorconfig"
64
+ - ".rspec"
65
+ - ".rubocop.yml"
66
+ - CHANGELOG.md
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - acclir.gemspec
73
+ - exe/acclir
74
+ - lib/acclir.rb
75
+ - lib/acclir/at_coder.rb
76
+ - lib/acclir/at_coder/contest.rb
77
+ - lib/acclir/at_coder/sample.rb
78
+ - lib/acclir/at_coder/task.rb
79
+ - lib/acclir/cli.rb
80
+ - lib/acclir/command/new.rb
81
+ - lib/acclir/templates/new/main_test.rb.tt
82
+ - lib/acclir/version.rb
83
+ - sig/acclir.rbs
84
+ homepage: https://github.com/n0h0/acclir
85
+ licenses:
86
+ - MIT
87
+ metadata:
88
+ homepage_uri: https://github.com/n0h0/acclir
89
+ source_code_uri: https://github.com/n0h0/acclir
90
+ changelog_uri: https://github.com/n0h0/acclir/blob/main/CHANGELOG.md
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 2.7.0
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.1.6
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: AtCoder CLI developed in Ruby.
110
+ test_files: []