green_day 0.4.0 → 0.5.0

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: 06bcfc1dc4b42165710a01e2d1d4836e0ad829a4b33040d5f35613b836ce15af
4
- data.tar.gz: 39899f57ae69c44e702b7a9a0990e332d8842867584fe97462f01d89edcae461
3
+ metadata.gz: f6db900740eb86bf00384ad3f97895ecd146d5f112f96db362c28a28cbfb391f
4
+ data.tar.gz: c4f4a09dd97c634b671434735896294c13f5ad3992d97378db3cde64e804efae
5
5
  SHA512:
6
- metadata.gz: 54eacd28a4a76464d6a740bc6b670ecf33c8f264cc33b3e32cd8943d6df3f5e85d822c21f09712cf339e0c5d8e2f43626a9d845c8f84c31e0d8b1e818aecfc8a
7
- data.tar.gz: 16e9b1390526d3d55ea2eeaef27f964844aaf23997236f108efecbc8bd2f781c04e04bef3b3a100248072205b075425eb09d7eb016cdbab7ddade4c3598cda2f
6
+ metadata.gz: 15d1dfd04be33f629ec7f6f74ff7666175e39bd62e3dcb80f2d5ae936c86001ba479db6fe2a084839d7e12fedaede50b3d85c9c65d4ae9c88700127204c4a33e
7
+ data.tar.gz: c5e5b31671f907460705f3baac9e9ebc6a0142fb3d2678e1783b3b8a382e266cb06cf4e793a096768632b8451f2925d6968550c32ae5ef355738f3ee23e8153c
@@ -0,0 +1,31 @@
1
+ name: Publish to RubyGems
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ jobs:
7
+ build:
8
+ name: Build + Publish
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ packages: write
12
+ contents: read
13
+
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - name: Set up Ruby 3.1
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 3.1
20
+ - run: bundle install
21
+
22
+ - name: Publish to RubyGems
23
+ run: |
24
+ mkdir -p $HOME/.gem
25
+ touch $HOME/.gem/credentials
26
+ chmod 0600 $HOME/.gem/credentials
27
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
28
+ gem build *.gemspec
29
+ gem push *.gem
30
+ env:
31
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -10,25 +10,34 @@ jobs:
10
10
  runs-on: ubuntu-latest
11
11
  strategy:
12
12
  matrix:
13
- ruby:
13
+ ruby-version:
14
14
  - 2.7.1 # AtCoder公式が使用しているrubyは2.7.1
15
- - 3.1.0
15
+ - 3.1
16
16
  steps:
17
- - uses: actions/checkout@v2
18
- - name: Set up Ruby ${{ matrix.ruby }}
17
+ - uses: actions/checkout@v3
18
+ - name: Set up Ruby ${{ matrix.ruby-version }}
19
19
  uses: ruby/setup-ruby@v1
20
20
  with:
21
- ruby-version: ${{ matrix.ruby }}
22
- - name: bundle install
21
+ ruby-version: ${{ matrix.ruby-version }}
22
+ - name: Bundle install
23
23
  run: bundle install
24
- - name: Rubocop
25
- run: bundle exec rubocop
26
- - name: Rspec
24
+ - name: Run Rspec
27
25
  env:
28
26
  USER_NAME: ${{ secrets.USER_NAME }}
29
27
  PASSWORD: ${{ secrets.PASSWORD }}
30
28
  CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
31
29
  run: script -e -c "rake spec"
30
+ rubocop:
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v3
34
+ - uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: 3.1
37
+ - name: Bundle install
38
+ run: bundle install
39
+ - name: Run rubocop
40
+ run: bundle exec rubocop
32
41
 
33
42
 
34
43
 
data/.rubocop.yml CHANGED
@@ -19,6 +19,6 @@ Metrics/BlockLength:
19
19
  RSpec/NamedSubject:
20
20
  Enabled: false
21
21
  RSpec/NestedGroups:
22
- Max: 4
22
+ Max: 7
23
23
  RSpec/ExampleLength:
24
- Enabled: false
24
+ Enabled: false
data/README.md CHANGED
@@ -52,8 +52,6 @@ For example
52
52
  Example of output spec
53
53
 
54
54
  ```ruby
55
- require 'rspec'
56
-
57
55
  RSpec.describe 'test' do
58
56
  it 'test with "2 900\\n"' do
59
57
  io = IO.popen("ruby abc150/A.rb", "w+")
@@ -94,4 +92,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
94
92
 
95
93
  ## Code of Conduct
96
94
 
97
- Everyone interacting in the GreenDay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/green_day/blob/master/CODE_OF_CONDUCT.md).
95
+ Everyone interacting in the GreenDay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/QWYNG/green_day/blob/master/CODE_OF_CONDUCT.md).
data/green_day.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ['lib']
28
28
 
29
29
  spec.add_dependency 'colorize'
30
- spec.add_dependency 'faraday', '< 1.0'
30
+ spec.add_dependency 'faraday'
31
31
  spec.add_dependency 'faraday-cookie_jar'
32
32
  spec.add_dependency 'nokogiri'
33
33
  spec.add_dependency 'parallel'
@@ -20,28 +20,9 @@ module GreenDay
20
20
  end
21
21
  end
22
22
 
23
- def contest_exist?(contest_name)
24
- res = client.get("contests/#{contest_name}")
25
- res.status == 200
26
- end
27
-
28
- def fetch_task_codes(contest)
29
- body = get_parsed_body("contests/#{contest.name}/tasks")
30
-
31
- # 3問だったら<tbody>の中に<tr>が3 * 2個 </tbody> が1mh個
32
- tasks_size = ((body.at('tbody').children.size - 1) / 2.0).ceil
33
- ('A'..'ZZ').to_a.shift(tasks_size)
34
- end
35
-
36
- def fetch_inputs_and_outputs(contest, task)
37
- contest_name = contest.name
38
- path = "contests/#{contest_name}/tasks/#{contest_name}_#{task.code.downcase}"
39
- body = get_parsed_body(path)
40
- samples = body.css('.lang-ja > .part > section > pre').map { |e| e.children.text }
41
-
42
- inputs, outputs = samples.partition.with_index { |_sample, i| i.even? }
43
-
44
- [inputs, outputs]
23
+ def get_parsed_body(path)
24
+ res = client.get(path)
25
+ Nokogiri::HTML.parse(res.body)
45
26
  end
46
27
 
47
28
  def login(username, password)
@@ -54,7 +35,7 @@ module GreenDay
54
35
 
55
36
  unless login_succeed?
56
37
  ## ex error:Username or Password is incorrect
57
- raise Error, CGI.unescape(select_flash_cookie.value).split('.').shift
38
+ raise Error, CGI.unescape(flash_cookie.value).split('.').shift
58
39
  end
59
40
 
60
41
  cookie_jar.save(COOKIE_FILE_NAME)
@@ -83,17 +64,13 @@ module GreenDay
83
64
  end
84
65
 
85
66
  def login_succeed?
86
- flash_cookie = select_flash_cookie
87
67
  flash_cookie.value.include?('Welcome')
88
68
  end
89
69
 
90
- def select_flash_cookie
91
- cookie_jar.store.instance_variable_get(:@jar)['atcoder.jp']['/']['REVEL_FLASH']
92
- end
93
-
94
- def get_parsed_body(path)
95
- res = client.get(path)
96
- Nokogiri::HTML.parse(res.body)
70
+ def flash_cookie
71
+ @flash_cookie ||= cookie_jar.cookies("#{ATCODER_ENDPOINT}/login").find do |cookie|
72
+ cookie.name == 'REVEL_FLASH'
73
+ end
97
74
  end
98
75
  end
99
76
  end
data/lib/green_day/cli.rb CHANGED
@@ -53,11 +53,11 @@ module GreenDay
53
53
  end
54
54
 
55
55
  def submit_file_path(task)
56
- "#{task.contest.name}/#{task.code}.rb"
56
+ "#{task.contest.name}/#{task.name}.rb"
57
57
  end
58
58
 
59
59
  def spec_file_path(task)
60
- "#{task.contest.name}/spec/#{task.code}_spec.rb"
60
+ "#{task.contest.name}/spec/#{task.name}_spec.rb"
61
61
  end
62
62
  end
63
63
  end
@@ -1,22 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'atcoder_client'
3
+ require 'forwardable'
4
4
  require_relative 'task'
5
5
 
6
6
  module GreenDay
7
7
  class Contest
8
- attr_reader :atcoder_client, :name, :tasks
8
+ extend Forwardable
9
+ delegate get_parsed_body: :@client
9
10
 
10
- def initialize(contest_name, client)
11
- raise GreenDay::Error 'cant find contest' unless client.contest_exist?(contest_name)
11
+ attr_reader :name, :tasks
12
12
 
13
+ def initialize(contest_name, client)
14
+ @client = client
13
15
  @name = contest_name
14
16
 
15
- task_codes = client.fetch_task_codes(self)
17
+ task_names_and_paths = fetch_task_names_and_paths
16
18
  @tasks =
17
- Parallel.map(task_codes, in_threads: THREAD_COUNT) do |task_code|
18
- Task.new(self, task_code, client)
19
+ Parallel.map(task_names_and_paths,
20
+ in_threads: THREAD_COUNT) do |task_name, task_path|
21
+ Task.new(self, task_name, task_path, @client)
19
22
  end
20
23
  end
24
+
25
+ private
26
+
27
+ def fetch_task_names_and_paths
28
+ body = get_parsed_body("contests/#{name}/tasks")
29
+ task_elements = body.search('tbody tr td:first a')
30
+
31
+ task_elements.to_h do |element|
32
+ [element.text, element[:href]]
33
+ end
34
+ end
21
35
  end
22
36
  end
@@ -1,22 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'forwardable'
4
+
3
5
  module GreenDay
4
6
  class Task
5
- attr_reader :contest, :code, :sample_answers
7
+ extend Forwardable
8
+ delegate get_parsed_body: :@client
9
+
10
+ attr_reader :contest, :name, :path, :sample_answers
6
11
 
7
- def initialize(contest, code, client)
12
+ def initialize(contest, name, path, client)
13
+ @client = client
8
14
  @contest = contest
9
- @code = code
10
- @sample_answers = create_sample_answers(client)
15
+ @name = name
16
+ @path = path
17
+ @sample_answers = create_sample_answers_hash
11
18
  end
12
19
 
13
20
  private
14
21
 
15
- def create_sample_answers(client)
16
- input_samples, output_samples =
17
- client.fetch_inputs_and_outputs(contest, self)
22
+ def create_sample_answers_hash
23
+ input_samples, output_samples = fetch_inputs_and_outputs
18
24
 
19
25
  input_samples.zip(output_samples).to_h
20
26
  end
27
+
28
+ def fetch_inputs_and_outputs
29
+ body = get_parsed_body(path)
30
+ samples = body.css('.lang-ja > .part > section > pre').map { |e| e.children.text }
31
+
32
+ inputs, outputs = samples.partition.with_index { |_sample, i| i.even? }
33
+
34
+ [inputs, outputs]
35
+ end
21
36
  end
22
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GreenDay
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: green_day
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - qwyng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2022-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "<"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "<"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: faraday-cookie_jar
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -242,6 +242,7 @@ executables:
242
242
  extensions: []
243
243
  extra_rdoc_files: []
244
244
  files:
245
+ - ".github/workflows/publish_to_rubygems.yml"
245
246
  - ".github/workflows/ruby.yml"
246
247
  - ".gitignore"
247
248
  - ".rspec"
@@ -284,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
284
285
  - !ruby/object:Gem::Version
285
286
  version: '0'
286
287
  requirements: []
287
- rubygems_version: 3.1.6
288
+ rubygems_version: 3.3.7
288
289
  signing_key:
289
290
  specification_version: 4
290
291
  summary: CLI tool for AtCoder and Ruby