jkf 0.5.1 → 0.5.2

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: 10de9aac464bd36cb02f25fe54861977cef819870cfe2b35d8f9741b119c3165
4
- data.tar.gz: 9a9271b5bf437c8d3a493732046ee3b86c50a4c26313c975a0041e9d8d91e290
3
+ metadata.gz: 365393f77c09c5ca61d79d520d1e8700449f66b9c5f8dd98f3c533d08b5205d6
4
+ data.tar.gz: de3a842b9d14005cfff7e9e4d41129b58d0fd9713b91def327e3e579c227498c
5
5
  SHA512:
6
- metadata.gz: 778bd58dffa3e570cb4f9a4f235518d402f8e135b1a33f7e3f3758d71807b3a6e0b9f77bda86ec6da478da9932a0dc242e3a979a2318f02c47dcd3023b899615
7
- data.tar.gz: 9f52cef3917dc571e3edd7bad14b6e3d8a3debd7da08dfa480f7b3861db7fbe23c63a4b7eb06c11f7322eec7176a7f08dcee29e216d5b7d6a51ef96ea484d470
6
+ metadata.gz: 290f7bd7bec9ccf530ae186a6ee5293827be45fb4b9c3e719d355044b00695d3656e62fd47111d7a7c031ed007d369b51f45518ba48b71a9e80b82dba2b093db
7
+ data.tar.gz: c6d9965c4d109352d9fab43dbc17647ded822e02ea24ff41755194c70f8523d7636b43b04df891e127d070bf235c93a63815749adda2b0780260f66778122442
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ use guix
data/.rubocop.yml CHANGED
@@ -7,6 +7,7 @@ AllCops:
7
7
  require:
8
8
  - rubocop-rake
9
9
  - rubocop-rspec
10
+ - rubocop-performance
10
11
 
11
12
  Style/FrozenStringLiteralComment:
12
13
  Enabled: true
@@ -63,3 +64,12 @@ Style/StringLiterals:
63
64
 
64
65
  Style/GuardClause:
65
66
  Enabled: true
67
+
68
+ Performance/StringInclude:
69
+ Enabled: true
70
+
71
+ Performance/RegexpMatch:
72
+ Enabled: true
73
+
74
+ Performance/MapCompact:
75
+ Enabled: true
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ -
2
+ README.md
3
+ README.en.md
4
+ CHANGELOG.md
data/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## 0.5.2 - 2024-10-26
11
+
12
+ This is a maintenance release.
13
+
14
+ ### Others
15
+
16
+ * Lint with RuboCop performance plugin
17
+ * Update documentation
18
+ * Update gem dependencies; RuboCop and RuboCop RSpec.
19
+
10
20
  ## [0.5.1] - 2023-06-24
11
21
 
12
22
  ### Changed
data/Gemfile CHANGED
@@ -5,17 +5,18 @@ gemspec
5
5
  gem 'rake'
6
6
 
7
7
  group :development do
8
- gem 'redcarpet', require: false
9
- gem 'yard', require: false
8
+ gem 'redcarpet'
9
+ gem 'yard'
10
10
 
11
- gem 'guard-rubocop', require: false
12
- gem 'rubocop', '~> 1.32.0', require: false
13
- gem 'rubocop-rake', '~> 0.6.0', require: false
14
- gem 'rubocop-rspec', '~> 2.12', require: false
11
+ gem 'guard-rubocop'
12
+ gem 'rubocop', '~> 1.63'
13
+ gem 'rubocop-performance'
14
+ gem 'rubocop-rake', '~> 0.6.0'
15
+ gem 'rubocop-rspec', '~> 3.1'
15
16
  end
16
17
 
17
18
  group :test do
18
- gem 'guard-rspec', require: false
19
- gem 'rspec', '~> 3.0', require: false
20
- gem 'simplecov', require: false
19
+ gem 'guard-rspec'
20
+ gem 'rspec', '~> 3.0'
21
+ gem 'simplecov'
21
22
  end
data/README.en.md CHANGED
@@ -1,37 +1,40 @@
1
- # Jkf
1
+ # jkf gem
2
+
2
3
  [![Gem
3
4
  Version](https://badge.fury.io/rb/jkf.svg)](https://badge.fury.io/rb/jkf)
4
5
  [![Build
5
6
  Status](https://travis-ci.org/iyuuya/jkf.svg?branch=master)](https://travis-ci.org/iyuuya/jkf)
6
7
  [![CI](https://github.com/iyuuya/jkf/actions/workflows/ci.yml/badge.svg)](https://github.com/iyuuya/jkf/actions/workflows/ci.yml)
7
8
 
8
- jkf is a Ruby port of [json-kifu-format][jkf].
9
- It supports both of the conversion from KIF, KI2, or CSA to jkf, and the one
10
- from jkf to KIF, KI2, or CSA.
9
+ The jkf gem is a Ruby port of [json-kifu-format (JKF)][jkf].
10
+ It supports both of the conversion from KIF (see [棋譜ファイル KIF 形式][kakinoki]),
11
+ KI2, or CSA (see [CSA標準棋譜ファイル形式][csa]) to JKF, and the one from JKF to KIF,
12
+ KI2, or CSA.
11
13
 
12
- [jkf]:https://github.com/na2hiro/Kifu-for-JS/tree/master/packages/json-kifu-format
14
+ [csa]: http://www2.computer-shogi.org/protocol/record_v22.html
15
+ [jkf]:
16
+ https://github.com/na2hiro/Kifu-for-JS/tree/master/packages/json-kifu-format
17
+ [kakinoki]: http://kakinoki.o.oo7.jp/kif_format.html
13
18
 
14
19
  ## Installation
15
20
 
16
- If you install this gem to your application (with Bundler), add this to
17
- Gemfile.
21
+ If you install this gem to your application (with [Bundler][bundler]), add
22
+ this to `Gemfile`.
23
+
24
+ [bundler]: https://bundler.io/
18
25
 
19
26
  ```ruby
20
27
  gem 'jkf'
21
28
  ```
22
29
 
23
- Then run bundle to install this gem.
24
-
25
- $ bundle
30
+ Then run `bundle` to install this gem.
26
31
 
27
- Or directly install with gem install command.
28
-
29
- $ gem install jkf
32
+ Or directly install with `gem install` command.
30
33
 
31
34
  ## Usage
32
35
 
33
- This gem has the Parser and the Converter for each formats: KIF, KI2, and
34
- CSA.
36
+ This gem has the parser {Jkf::Parser} and the converter {Jkf::Converter} for
37
+ each formats: KIF, KI2, and CSA.
35
38
 
36
39
  ```ruby
37
40
  kif_parser = Jkf::Parser::Kif.new
@@ -45,8 +48,8 @@ ki2_converter = Jkf::Converter::Ki2.new
45
48
  csa_converter = Jkf::Converter::Csa.new
46
49
  ```
47
50
 
48
- `parser#parse(str)` to convert into jkf.
49
- `#convert(jkf)` to convert into each formats from jkf.
51
+ {Jkf::Parser::Base#parse} to convert into JKF.
52
+ {Jkf::Converter::Base#convert} to convert into each formats from JKF.
50
53
 
51
54
  ```ruby
52
55
  jkf = kif_parser.parse(kif_str) #=> Hash
@@ -62,13 +65,15 @@ csa = csa_converter.convert(jkf) #=> String
62
65
 
63
66
  ## Contributing
64
67
 
65
- Feel free to report bugs or send pull requests at
66
- [GitHub](https://github.com/iyuuya/jkf).
68
+ Feel free to report bugs or send pull requests at [the GitHub
69
+ repository][repo].
70
+
71
+ [repo]: https://github.com/iyuuya/jkf
67
72
 
68
73
  If you work on Guix, run tests by `guix shell`.
69
74
 
70
75
  ## License
71
76
 
72
- This gem is licensed under the [MIT
73
- License](http://opensource.org/licenses/MIT).
77
+ This gem is provided under the [MIT License][mit].
74
78
 
79
+ [mit]: http://opensource.org/licenses/MIT
data/README.md CHANGED
@@ -1,30 +1,31 @@
1
- # Jkf
1
+ # jkf gem
2
+
2
3
  [![Gem Version](https://badge.fury.io/rb/jkf.svg)](https://badge.fury.io/rb/jkf) [![Build Status](https://travis-ci.org/iyuuya/jkf.svg?branch=master)](https://travis-ci.org/iyuuya/jkf) [![CI](https://github.com/iyuuya/jkf/actions/workflows/ci.yml/badge.svg)](https://github.com/iyuuya/jkf/actions/workflows/ci.yml)
3
4
 
4
- jkfは[JSON棋譜フォーマット (JKF)][jkf]をRubyに移植したものです。
5
- KIF, KI2, CSAをパースしJKFへ変換、JKFからKIF, KI2, CSAへの変換に対応しています。
5
+ jkf gemは[JSON棋譜フォーマット (JKF)][jkf]をRubyに移植したものです。
6
+ 柿木形式([棋譜ファイル KIF 形式][kakinoki]、KI2)、[CSA標準棋譜ファイル形式][csa]の構文解析とJKFへの変換、JKFからKIF, KI2, CSAへの変換に対応しています。
6
7
 
8
+ [csa]: http://www2.computer-shogi.org/protocol/record_v22.html
7
9
  [jkf]: https://github.com/na2hiro/Kifu-for-JS/tree/master/packages/json-kifu-format
10
+ [kakinoki]: http://kakinoki.o.oo7.jp/kif_format.html
11
+
12
+ ## インストール
8
13
 
9
- ## Installation
14
+ アプリケーションにインストールする場合([Bundler][bundler]を使用する場合)、`Gemfile`に以下のように記述してください。
10
15
 
11
- アプリケーションにインストールする場合(bundlerを使用する場合)、Gemfileに以下のように記述してください。
16
+ [bundler]: https://bundler.io/
12
17
 
13
18
  ```ruby
14
19
  gem 'jkf'
15
20
  ```
16
21
 
17
- さらにbundleコマンドを実行することでインストールできます。
18
-
19
- $ bundle
22
+ さらに`bundle`コマンドを実行することでインストールできます。
20
23
 
21
- または、gem installコマンドを使って直接インストールすることもできます。
24
+ または、`gem install`コマンドを使って直接インストールもできます。
22
25
 
23
- $ gem install jkf
26
+ ## 使い方
24
27
 
25
- ## Usage
26
-
27
- KIF, KI2, CSAそれぞれParserとConverterが用意してあります。
28
+ KIF, KI2, CSAそれぞれ構文解析器 {Jkf::Parser} と変換器 {Jkf::Converter} が用意してあります。
28
29
 
29
30
  ```ruby
30
31
  kif_parser = Jkf::Parser::Kif.new
@@ -38,7 +39,7 @@ ki2_converter = Jkf::Converter::Ki2.new
38
39
  csa_converter = Jkf::Converter::Csa.new
39
40
  ```
40
41
 
41
- `parser#parse(str)`でjkfへの変換、`#convert(jkf)`でjkfから各フォーマットへ変換できます。
42
+ {Jkf::Parser::Base#parse} でJKFへの変換、 {Jkf::Converter::Base#convert} でJKFから各形式へ変換できます。
42
43
 
43
44
  ```ruby
44
45
  jkf = kif_parser.parse(kif_str) #=> Hash
@@ -52,15 +53,23 @@ ki2 = ki2_converter.convert(jkf) #=> String
52
53
  csa = csa_converter.convert(jkf) #=> String
53
54
  ```
54
55
 
55
- ## Contributing
56
+ ## 貢献
57
+
58
+ バグレポートやプルリクエストは[GitHubのリポジトリ][repo]でよろしくお願いします。
56
59
 
57
- バグレポートやプルリクエストはGithubでよろしくお願いします。
58
- https://github.com/iyuuya/jkf.
60
+ [repo]: https://github.com/iyuuya/jkf
59
61
 
60
62
  Guixで開発されている場合は`guix shell`で`rake test`によるテスト実行ができます。
61
63
 
62
- ## License
64
+ 翻訳はドキュメントとAPIの2種類があります。
65
+ APIについてはRDocの国際化の機能を使います。
66
+ POTファイルの生成には`rdoc --format pot`とします。
67
+ これにより`doc/rdoc.pot`が生成されます。
68
+ このPOTファイルから各言語のPOファイルを初期化できます。
69
+ 例えば`msginit -i doc/rdoc.pot -o po/en.rdoc.po --locale en_US.UTF-8`です。
70
+
71
+ ## 利用許諾
63
72
 
64
- ライセンスはMITです。
65
- [MIT License](http://opensource.org/licenses/MIT).
73
+ ライセンスは[MIT License][mit]です。
66
74
 
75
+ [mit]: http://opensource.org/licenses/MIT
data/bench.rb CHANGED
@@ -2,7 +2,7 @@ require 'benchmark/ips'
2
2
  require_relative 'lib/jkf'
3
3
 
4
4
  Benchmark.ips do |x|
5
- x.report("parse") do
5
+ x.report('parse') do
6
6
  Dir['spec/*fixtures/**/*'].each do |file|
7
7
  Jkf.parse_file(file)
8
8
  rescue Jkf::FileTypeError, Jkf::Parser::ParseError
data/jkf.gemspec CHANGED
@@ -5,19 +5,21 @@ require 'jkf/version'
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'jkf'
7
7
  spec.version = Jkf::VERSION
8
- spec.authors = ['iyuuya']
9
- spec.email = ['i.yuuya@gmail.com']
8
+ spec.authors = ['iyuuya', 'gemmaro']
9
+ spec.email = ['i.yuuya@gmail.com', 'gemmaro.dev@gmail.com']
10
10
 
11
- spec.summary = 'jkf/csa/kif/ki2 parser and converter'
12
- spec.description = 'converter/parser of records of shogi'
11
+ spec.summary = 'Shogi formats parser and converter'
12
+ spec.description = 'The jkf gem provides parsers and converters (generaters) for several shogi formats.'
13
13
  spec.homepage = 'https://github.com/iyuuya/jkf'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.required_ruby_version = '>= 3.0'
17
17
 
18
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- spec.bindir = 'exe'
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
19
  spec.require_paths = ['lib']
22
- spec.metadata['rubygems_mfa_required'] = 'true'
20
+
21
+ spec.metadata = {
22
+ 'rubygems_mfa_required' => 'true',
23
+ 'documentation_uri' => 'https://www.rubydoc.info/gems/jkf'
24
+ }
23
25
  end
@@ -24,20 +24,20 @@ module Jkf
24
24
  end
25
25
 
26
26
  def convert_header(header)
27
- header.map do |(key, value)|
27
+ header.filter_map do |(key, value)|
28
28
  result = add_header(key, value)
29
- if key =~ /\A[先後上下]手\Z/
29
+ if /\A[先後上下]手\Z/.match?(key)
30
30
  nil
31
31
  else
32
32
  result
33
33
  end
34
- end.compact.join
34
+ end.join
35
35
  end
36
36
 
37
37
  def add_header(key, value)
38
38
  result = "#{key}:#{value}\n"
39
- if key =~ /\A[先後上下]手\Z/
40
- if key =~ /[先下]/
39
+ if /\A[先後上下]手\Z/.match?(key)
40
+ if /[先下]/.match?(key)
41
41
  @header2.unshift result
42
42
  else
43
43
  @header2 << result
@@ -25,10 +25,10 @@ module Jkf
25
25
  end
26
26
 
27
27
  def convert_header(header, jkf)
28
- header.map do |(key, value)|
28
+ header.filter_map do |(key, value)|
29
29
  result = "#{key}:#{value}\n"
30
- if key =~ /\A[先後上下]手\Z/
31
- if key =~ /[先下]/
30
+ if /\A[先後上下]手\Z/.match?(key)
31
+ if /[先下]/.match?(key)
32
32
  @header2.unshift result
33
33
  else
34
34
  @header2 << result
@@ -39,7 +39,7 @@ module Jkf
39
39
  else
40
40
  result
41
41
  end
42
- end.compact.join
42
+ end.join
43
43
  end
44
44
 
45
45
  def convert_moves(moves, idx = 0)
@@ -52,7 +52,7 @@ module Jkf
52
52
  end
53
53
 
54
54
  def convert_motigoma(pieces)
55
- pieces.to_a.reverse.map do |(piece, num)|
55
+ pieces.to_a.reverse.filter_map do |(piece, num)|
56
56
  if num > 0
57
57
  str = csa2kind(piece)
58
58
  if num > 1
@@ -62,7 +62,7 @@ module Jkf
62
62
  end
63
63
  str
64
64
  end
65
- end.compact.join(' ') + " \n"
65
+ end.join(' ') + " \n"
66
66
  end
67
67
 
68
68
  def convert_board_piece(piece)
@@ -81,7 +81,7 @@ module Jkf
81
81
  def convert_special(special, index)
82
82
  result = "まで#{index + 1}手"
83
83
 
84
- if special == 'TORYO' || special =~ /ILLEGAL/
84
+ if special == 'TORYO' || special.include?('ILLEGAL')
85
85
  turn = @players[index % 2]
86
86
  result += "で#{turn}手の"
87
87
  result += { 'TORYO' => '勝ち',
@@ -92,7 +92,7 @@ module Jkf
92
92
  end
93
93
  end
94
94
 
95
- def record_failure(expected)
95
+ def record_failure(_expected)
96
96
  return if @scanner.pos < @max_fail_pos
97
97
 
98
98
  return unless @scanner.pos > @max_fail_pos
@@ -6,7 +6,7 @@ module Jkf
6
6
 
7
7
  # kifu : csa2 | csa1
8
8
  def parse_root
9
- @scanner << "\n" unless @scanner.string[-1] =~ /\n|\r|,/ # FIXME
9
+ @scanner << "\n" unless /\n|\r|,/.match?(@scanner.string[-1]) # FIXME
10
10
  s0 = parse_csa2
11
11
  s0 = parse_csa1 if s0 == :failed
12
12
  s0
data/lib/jkf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jkf
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
data/manifest.scm CHANGED
@@ -49,34 +49,6 @@ RuboCop when files are modified.")
49
49
  (home-page "https://github.com/guard/guard-compat")
50
50
  (license license:expat)))
51
51
 
52
- (define-public ruby-ruby-dep
53
- (package
54
- (name "ruby-ruby-dep")
55
- (version "1.5.0")
56
- (source (origin
57
- (method git-fetch)
58
- (uri (git-reference
59
- (url "https://github.com/e2/ruby_dep")
60
- (commit "4e79416a55dff4b3ff50e73c8fbd0455de1e68b7")))
61
- (file-name (git-file-name name version))
62
- (sha256
63
- (base32
64
- "0vv2bm4lghh5pl8zi0ihp6hpbp7xlk8d5h888nhxr725in0ypy9x"))))
65
- (build-system ruby-build-system)
66
- (arguments
67
- `(#:test-target "spec"
68
- #:tests? #f ;FIXME: needs gem_isolator, but cyclic dependencies
69
- ))
70
- (native-inputs (list ruby-rspec))
71
- (synopsis
72
- "Creates a version constraint of supported Rubies, suitable for a
73
- gemspec file")
74
- (description
75
- "This package creates a version constraint of supported Rubies,
76
- suitable for a gemspec file.")
77
- (home-page "https://github.com/e2/ruby_dep")
78
- (license license:expat)))
79
-
80
52
  (define-public ruby-gem-isolator
81
53
  (package
82
54
  (name "ruby-gem-isolator")
@@ -96,7 +68,7 @@ suitable for a gemspec file.")
96
68
  #:tests? #f ;FIXME: uninitialized constant Pathname
97
69
  ))
98
70
  (native-inputs (list ruby-rspec ruby-nenv ruby-rubocop))
99
- (propagated-inputs (list ruby-ruby-dep))
71
+ (propagated-inputs (list ruby-dep))
100
72
  (synopsis
101
73
  "Good for testing dependencies of a gem and/or different gem version
102
74
  combinations")
@@ -137,7 +109,7 @@ different gem version combinations.")
137
109
  ruby-rubocop-rake
138
110
  ruby-rubocop-rspec
139
111
  ruby-rspec
140
- ruby-guard-rspec
141
112
  ruby-simplecov
142
113
  ruby-benchmark-ips
114
+ ruby-rubocop-performance
143
115
  ruby))