green_day 0.1.6 → 0.3.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: 7f5b0679f10107fc35099cf83129628c78a00ae6eba65897a2220834be605a31
4
- data.tar.gz: 46a41ff725c660eccf8561048da49cfb05997ec8cbf7b24c58f9922fef87b166
3
+ metadata.gz: dec8f7c9c721bbd5e652f18959de01d9a90d6ec3a1d7caf57eed76aa31ad9378
4
+ data.tar.gz: c2afef234af2730e3a2ac2fff659dcfc85489b0292d2395f6382bab3a73d2f37
5
5
  SHA512:
6
- metadata.gz: ecc4dfeed26338f8bc22ad7e0e6380b82a523b86d3f0ae7352be6567027869baa1ff00f5c6694aa886145d863c9e30cc2cf816718d4ff9cb8d0516f4df1a6a28
7
- data.tar.gz: 3651746ff097ccc98e359a3fe5ee941cfe2aefede5969990171d0d7e79bf86ae2edafd3ea6a2bb46eea9673fa54cbb6db8abaa36534768bc17763689da0c2b70
6
+ metadata.gz: 9a6f108363c5e35d96b5739184318260d64da36187a259449ac5fde602d6d70a16d7bfab01f64f4a8794fcbbfa49322bdfb13ae408a7ffd0299820a5eac2f806
7
+ data.tar.gz: 9e6d545f778fd361853c082fcd1d67564d59edef0bbe88ac2f47189c0bcc1b1c4603f35374cf0d8728c455b8c0ed33f18e96eb54ddf5e8432a72a688d1684de8
@@ -1,60 +1,28 @@
1
1
  name: Ruby
2
2
 
3
- on: [push]
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [ master ]
4
7
 
5
8
  jobs:
6
- build:
7
-
8
- runs-on: ${{ matrix.runner }}
9
-
9
+ rspec:
10
+ runs-on: ubuntu-latest
10
11
  strategy:
11
- fail-fast: false
12
-
13
12
  matrix:
14
13
  ruby:
15
- - 2.3.3
16
- - 2.7.0
17
- include:
18
- - ruby: 2.3.3
19
- runner: ubuntu-16.04
20
- - ruby: 2.7.0
21
- runner: ubuntu-latest
22
-
14
+ - 2.7.1
23
15
  steps:
24
16
  - uses: actions/checkout@v2
25
-
26
- - name: Set up rbenv
27
- uses: masa-iwasaki/setup-rbenv@1.1.0
28
-
29
- - name: Cache RBENV_ROOT
30
- uses: actions/cache@v1
31
- id: cache_rbenv
17
+ - name: Set up Ruby ${{ matrix.ruby }}
18
+ uses: actions/setup-ruby@v1
32
19
  with:
33
- path: ~/.rbenv/versions
34
- key: v1-rbenv-${{ runner.os }}-${{ matrix.ruby }}
35
-
36
- - name: Reinstall libssl-dev
37
- run: |
38
- set -xe
39
- sudo apt-get remove -y libssl-dev
40
- sudo apt-get install -y libssl-dev=1.0.2g-1ubuntu4.15
41
- if: matrix.runner == 'ubuntu-16.04'
42
-
43
- - name: Install Ruby
44
- env:
45
- RBENV_VERSION: ${{ matrix.ruby }}
46
- run: |
47
- set -xe
48
- eval "$(rbenv init -)"
49
- rbenv install -s $RBENV_VERSION
50
- gem install bundler || true
51
-
52
- - name: test with Rake
20
+ ruby-version: ${{ matrix.ruby }}
21
+ - name: Rspec with rake
53
22
  env:
54
23
  USER_NAME: ${{ secrets.USER_NAME }}
55
24
  PASSWORD: ${{ secrets.PASSWORD }}
56
- RBENV_VERSION: ${{ matrix.ruby }}
25
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
57
26
  run: |
58
- eval "$(rbenv init -)"
59
27
  bundle install --jobs 4 --retry 3
60
- bundle exec rake
28
+ script -e -c rake
@@ -10,4 +10,4 @@ Layout/LineLength:
10
10
  Metrics/BlockLength:
11
11
  Exclude:
12
12
  - 'spec/*'
13
-
13
+ - 'green_day.gemspec'
data/README.md CHANGED
@@ -18,11 +18,11 @@ Or install it yourself as:
18
18
  $ gem install green_day
19
19
 
20
20
  ## Usage
21
- login(this command stores your cookie as `cookie-store` in current directory)
21
+ login(this command stores your cookie as `.cookie-store` in current directory)
22
22
 
23
23
  $ bundle exec green_day login
24
24
 
25
- If you want to delete session, remove `cookie-store`
25
+ If you want to delete session, remove `.cookie-store`
26
26
 
27
27
  This command creates directory and spec.
28
28
 
@@ -25,13 +25,16 @@ Gem::Specification.new do |spec|
25
25
  spec.bindir = 'exe'
26
26
  spec.require_paths = ['lib']
27
27
 
28
+ spec.add_dependency 'colorize'
28
29
  spec.add_dependency 'faraday', '< 1.0'
29
30
  spec.add_dependency 'faraday-cookie_jar'
30
31
  spec.add_dependency 'nokogiri'
32
+ spec.add_dependency 'parallel'
31
33
  spec.add_dependency 'rspec', '~> 3.0'
32
34
  spec.add_dependency 'thor'
33
35
  spec.add_development_dependency 'bundler', '~> 2.0'
36
+ spec.add_development_dependency 'codecov'
34
37
  spec.add_development_dependency 'dotenv'
35
- spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rake', '>= 12.3.3'
36
39
  spec.add_development_dependency 'rubocop'
37
40
  end
@@ -8,7 +8,7 @@ require 'nokogiri'
8
8
  module GreenDay
9
9
  class AtcoderClient
10
10
  ATCODER_ENDPOINT = 'https://atcoder.jp'
11
- COOKIE_DB = 'cookie-store'
11
+ COOKIE_FILE_NAME = '.cookie-store'
12
12
  attr_reader :client, :cookie_jar
13
13
 
14
14
  def initialize
@@ -57,14 +57,20 @@ module GreenDay
57
57
  raise Error, CGI.unescape(select_flash_cookie.value).split('.').shift
58
58
  end
59
59
 
60
- cookie_jar.save(COOKIE_DB)
60
+ cookie_jar.save(COOKIE_FILE_NAME)
61
61
  end
62
62
 
63
63
  private
64
64
 
65
65
  def create_or_load_cookie_jar
66
66
  jar = HTTP::CookieJar.new
67
- jar.load(COOKIE_DB) if File.exist?(COOKIE_DB)
67
+ if File.exist?(COOKIE_FILE_NAME)
68
+ jar.load(COOKIE_FILE_NAME)
69
+ elsif File.exist?('cookie-store')
70
+ warn 'cookie-store needs rename .cookie-store'
71
+ jar.load('cookie-store')
72
+ end
73
+
68
74
  jar
69
75
  end
70
76
 
@@ -1,37 +1,68 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'thor'
4
+ require 'parallel'
5
+ require 'colorize'
4
6
  require 'io/console'
5
7
  require_relative 'atcoder_client'
6
8
  require_relative 'contest'
7
9
  require_relative 'test_builder'
10
+ require_relative 'snippet_builder'
8
11
 
9
12
  module GreenDay
10
13
  class Cli < Thor
11
14
  desc 'login Atcoder', 'login Atcoder and save session'
12
15
  def login
13
16
  print 'username:'
14
- username = STDIN.gets.chomp!
17
+ username = STDIN.gets(chomp: true)
15
18
  print 'password:'
16
- password = STDIN.gets.chomp!
19
+ password = STDIN.noecho { |stdin| stdin.gets(chomp: true) }.tap { puts }
17
20
 
18
21
  AtcoderClient.new.login(username, password)
22
+ puts(
23
+ "Successfully created #{AtcoderClient::COOKIE_FILE_NAME}"
24
+ .colorize(:green)
25
+ )
19
26
  end
20
27
 
21
28
  desc 'new [contest name]', 'create contest workspace and spec'
22
29
  def new(contest_name)
23
- contest = Contest.new(contest_name)
30
+ contest = Contest.new(contest_name, AtcoderClient.new)
24
31
  FileUtils.makedirs("#{contest_name}/spec")
25
32
 
26
- contest.tasks.each do |task|
27
- task_code = task.code
28
- answer = File.open("#{contest_name}/#{task_code}.rb", 'w')
29
- test = TestBuilder.build_test(answer, task.input_output_hash)
33
+ Parallel.each(contest.tasks) do |task|
34
+ create_submit_file!(contest_name, task)
35
+ create_spec_file!(contest_name, task)
36
+ end
37
+
38
+ puts "Successfully created #{contest_name} directory".colorize(:green)
39
+ end
30
40
 
31
- File.open("#{contest.name}/spec/#{task_code}_spec.rb", 'w') do |f|
32
- f.write(test)
33
- end
41
+ private
42
+
43
+ def create_submit_file!(contest_name, task)
44
+ File.open(submit_file_path(contest_name, task), 'w') do |f|
45
+ f.write(SnippetBuilder.build)
34
46
  end
35
47
  end
48
+
49
+ def create_spec_file!(contest_name, task)
50
+ test =
51
+ TestBuilder.build_test(
52
+ submit_file_path(contest_name, task),
53
+ task.input_output_hash
54
+ )
55
+ File.open(spec_file_path(contest_name, task), 'w') do |f|
56
+ f.write(test)
57
+ end
58
+ end
59
+
60
+ def submit_file_path(contest_name, task)
61
+ "#{contest_name}/#{task.code}.rb"
62
+ end
63
+
64
+ def spec_file_path(contest_name, task)
65
+ "#{contest_name}/spec/#{task.code}_spec.rb"
66
+ end
36
67
  end
37
68
  end
@@ -7,13 +7,12 @@ module GreenDay
7
7
  class Contest
8
8
  attr_reader :atcoder_client, :name, :tasks
9
9
 
10
- def initialize(contest_name)
11
- client = AtcoderClient.new
10
+ def initialize(contest_name, client)
12
11
  raise GreenDay::Error 'cant find contest' unless client.contest_exist?(contest_name)
13
12
 
14
13
  @name = contest_name
15
- @tasks = client.fetch_task_codes(self).map do |task_code|
16
- Task.new(self, task_code)
14
+ @tasks = Parallel.map(client.fetch_task_codes(self)) do |task_code|
15
+ Task.new(self, task_code, client)
17
16
  end
18
17
  end
19
18
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GreenDay
4
+ module SnippetBuilder
5
+ ARRAY_INPUT_SNIPPET = 'gets.split.map(&:to_i)'
6
+ MULTIPLE_LINE_INPUT_SNIPPET =
7
+ 'readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }'
8
+
9
+ module_function
10
+
11
+ def build
12
+ [ARRAY_INPUT_SNIPPET, MULTIPLE_LINE_INPUT_SNIPPET]
13
+ .map { |snippet| '# ' + snippet }
14
+ .join("\n") + "\n"
15
+ end
16
+ end
17
+ end
@@ -3,17 +3,15 @@
3
3
  module GreenDay
4
4
  class Task
5
5
  attr_reader :contest, :code, :input_output_hash
6
- def initialize(contest, code)
6
+ def initialize(contest, code, client)
7
7
  @contest = contest
8
8
  @code = code
9
- @input_output_hash = create_input_output_hash
9
+ @input_output_hash = create_input_output_hash(client)
10
10
  end
11
11
 
12
12
  private
13
13
 
14
- def create_input_output_hash
15
- client = AtcoderClient.new
16
-
14
+ def create_input_output_hash(client)
17
15
  input_samples, output_samples =
18
16
  client.fetch_inputs_and_outputs(contest, self)
19
17
 
@@ -4,20 +4,20 @@ module GreenDay
4
4
  module TestBuilder
5
5
  module_function
6
6
 
7
- def build_test(answer, input_output_hash)
7
+ def build_test(submit_file_path, input_output_hash)
8
8
  <<~SPEC
9
9
  require 'rspec'
10
10
 
11
11
  RSpec.describe 'test' do
12
- #{input_output_hash.map { |input, output| build_example(answer, input, output) }.join("\n")}
12
+ #{input_output_hash.map { |input, output| build_example(submit_file_path, input, output) }.join("\n")}
13
13
  end
14
14
  SPEC
15
15
  end
16
16
 
17
- def build_example(answer, input, output)
17
+ def build_example(submit_file_path, input, output)
18
18
  <<~SPEC
19
19
  #{tab}it 'test with #{unify_cr_lf(input)}' do
20
- #{tab}#{tab}io = IO.popen("ruby #{answer.path}", "w+")
20
+ #{tab}#{tab}io = IO.popen("ruby #{submit_file_path}", "w+")
21
21
  #{tab}#{tab}io.puts(#{unify_cr_lf(input)})
22
22
  #{tab}#{tab}io.close_write
23
23
  #{tab}#{tab}expect(io.readlines.join).to eq(#{unify_cr_lf(output)})
@@ -26,6 +26,8 @@ module GreenDay
26
26
  end
27
27
 
28
28
  def unify_cr_lf(string)
29
+ return unless string # たまに画像で例を出してくるとsampleの文字がなくなる
30
+
29
31
  string.gsub(/\R/, "\n").dump
30
32
  end
31
33
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GreenDay
4
- VERSION = '0.1.6'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: green_day
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - qwyng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-18 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: faraday
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: parallel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rspec
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +122,20 @@ dependencies:
94
122
  - - "~>"
95
123
  - !ruby/object:Gem::Version
96
124
  version: '2.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: codecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
97
139
  - !ruby/object:Gem::Dependency
98
140
  name: dotenv
99
141
  requirement: !ruby/object:Gem::Requirement
@@ -112,16 +154,16 @@ dependencies:
112
154
  name: rake
113
155
  requirement: !ruby/object:Gem::Requirement
114
156
  requirements:
115
- - - "~>"
157
+ - - ">="
116
158
  - !ruby/object:Gem::Version
117
- version: '10.0'
159
+ version: 12.3.3
118
160
  type: :development
119
161
  prerelease: false
120
162
  version_requirements: !ruby/object:Gem::Requirement
121
163
  requirements:
122
- - - "~>"
164
+ - - ">="
123
165
  - !ruby/object:Gem::Version
124
- version: '10.0'
166
+ version: 12.3.3
125
167
  - !ruby/object:Gem::Dependency
126
168
  name: rubocop
127
169
  requirement: !ruby/object:Gem::Requirement
@@ -162,6 +204,7 @@ files:
162
204
  - lib/green_day/atcoder_client.rb
163
205
  - lib/green_day/cli.rb
164
206
  - lib/green_day/contest.rb
207
+ - lib/green_day/snippet_builder.rb
165
208
  - lib/green_day/task.rb
166
209
  - lib/green_day/test_builder.rb
167
210
  - lib/green_day/version.rb