jkf 0.4.3 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rubocop_todo.yml CHANGED
@@ -1,11 +1,7 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-02-24 04:22:16 +0900 using RuboCop version 0.37.2.
3
+ # on 2023-06-18 08:39:04 UTC using RuboCop version 1.48.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 30
10
- Metrics/AbcSize:
11
- Max: 127
data/CHANGELOG.md ADDED
@@ -0,0 +1,63 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.5.1] - 2023-06-24
11
+
12
+ ### Changed
13
+
14
+ * Update required Ruby version to 3.0 (security fix only stable
15
+ version), although the library itself might works with older Ruby
16
+ versions.
17
+
18
+ ### Others
19
+
20
+ * Refactor parser with StringScanner. This makes parser approx. 5x
21
+ faster.
22
+ * Fixed link to json-kifu-format
23
+ * Remove Inch CI link on readmes
24
+ * Lint Ruby sources
25
+ * Add benchmark script
26
+
27
+ ## [0.5.0] - 2023-06-18
28
+
29
+ ### Changed
30
+
31
+ * Set required Ruby version to 2.7; this will be updated to 3.0 or
32
+ later in the next release.
33
+
34
+ ### Fixed
35
+
36
+ * Remove `Fixnum` usage with integrated `Integer` for Ruby 3.2 or
37
+ later.
38
+
39
+ ### Others
40
+
41
+ * Remove Rake version constraint
42
+ * Support development on Guix
43
+ * Enable RubyGems MFA required to true (for maintainers)
44
+
45
+ Documents:
46
+
47
+ * Fixed readme usages
48
+ * Update English readme; introduce translation management
49
+ * Update readme links about CI or code coverage services
50
+
51
+ CI:
52
+
53
+ * Migrate CI from Travis CI to GitHub Actions
54
+ * Migrate from Code Climate to SimpleCov
55
+
56
+ Lint tool:
57
+
58
+ * Update RuboCop versin and config
59
+ * Lint source codes with RuboCop
60
+
61
+ and,
62
+
63
+ * Add this changelog
data/Gemfile CHANGED
@@ -1,19 +1,21 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem "rake", "~> 10.0"
5
+ gem 'rake'
6
6
 
7
7
  group :development do
8
- gem "yard", require: false
9
- gem "redcarpet", require: false
8
+ gem 'redcarpet', require: false
9
+ gem 'yard', require: false
10
10
 
11
- gem "rubocop", "~> 0.37.2", require: false
12
- gem "guard-rubocop", require: false
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
13
15
  end
14
16
 
15
17
  group :test do
16
- gem "codeclimate-test-reporter", require: nil
17
- gem "rspec", "~> 3.0", require: false
18
- gem "guard-rspec", require: false
18
+ gem 'guard-rspec', require: false
19
+ gem 'rspec', '~> 3.0', require: false
20
+ gem 'simplecov', require: false
19
21
  end
data/Guardfile CHANGED
@@ -3,8 +3,8 @@ scope(groups: %w(specs))
3
3
  directories %w(spec lib)
4
4
 
5
5
  group :specs, halt_on_fail: true do
6
- guard :rspec, cmd: "bundle exec rspec", failed_mode: :keep do
7
- require "guard/rspec/dsl"
6
+ guard :rspec, cmd: 'bundle exec rspec', failed_mode: :keep do
7
+ require 'guard/rspec/dsl'
8
8
  dsl = Guard::RSpec::Dsl.new(self)
9
9
 
10
10
  # RSpec files
@@ -18,7 +18,7 @@ group :specs, halt_on_fail: true do
18
18
  dsl.watch_spec_files_for(ruby.lib_files)
19
19
  end
20
20
 
21
- guard :rubocop, all_on_start: false, cli: "--rails" do
21
+ guard :rubocop, all_on_start: false, cli: '--rails' do
22
22
  watch(%r{.+\.rb$}) { |m| m[0] }
23
23
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
24
24
  end
data/README.en.md CHANGED
@@ -1,32 +1,38 @@
1
1
  # Jkf
2
- [![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) [![Code Climate](https://codeclimate.com/github/iyuuya/jkf/badges/gpa.svg)](https://codeclimate.com/github/iyuuya/jkf) [![Test Coverage](https://codeclimate.com/github/iyuuya/jkf/badges/coverage.svg)](https://codeclimate.com/github/iyuuya/jkf/coverage) [![Inline docs](http://inch-ci.org/github/iyuuya/jkf.svg?branch=develop)](http://inch-ci.org/github/iyuuya/jkf)
2
+ [![Gem
3
+ Version](https://badge.fury.io/rb/jkf.svg)](https://badge.fury.io/rb/jkf)
4
+ [![Build
5
+ Status](https://travis-ci.org/iyuuya/jkf.svg?branch=master)](https://travis-ci.org/iyuuya/jkf)
6
+ [![CI](https://github.com/iyuuya/jkf/actions/workflows/ci.yml/badge.svg)](https://github.com/iyuuya/jkf/actions/workflows/ci.yml)
3
7
 
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.
4
11
 
5
- jkf is json-kifu-format( https://github.com/na2hiro/json-kifu-format ) library for ruby.
6
-
7
- ### Feature
8
-
9
- * KIF, KI2, CSA to JKF
10
- * JKF to KIF, KI2, CSA
12
+ [jkf]:https://github.com/na2hiro/Kifu-for-JS/tree/master/packages/json-kifu-format
11
13
 
12
14
  ## Installation
13
15
 
14
- Add this line to your application's Gemfile:
16
+ If you install this gem to your application (with Bundler), add this to
17
+ Gemfile.
15
18
 
16
19
  ```ruby
17
20
  gem 'jkf'
18
21
  ```
19
22
 
20
- And then execute:
23
+ Then run bundle to install this gem.
21
24
 
22
25
  $ bundle
23
26
 
24
- Or install it yourself as:
27
+ Or directly install with gem install command.
25
28
 
26
29
  $ gem install jkf
27
30
 
28
31
  ## Usage
29
32
 
33
+ This gem has the Parser and the Converter for each formats: KIF, KI2, and
34
+ CSA.
35
+
30
36
  ```ruby
31
37
  kif_parser = Jkf::Parser::Kif.new
32
38
  ki2_parser = Jkf::Parser::Ki2.new
@@ -39,6 +45,9 @@ ki2_converter = Jkf::Converter::Ki2.new
39
45
  csa_converter = Jkf::Converter::Csa.new
40
46
  ```
41
47
 
48
+ `parser#parse(str)` to convert into jkf.
49
+ `#convert(jkf)` to convert into each formats from jkf.
50
+
42
51
  ```ruby
43
52
  jkf = kif_parser.parse(kif_str) #=> Hash
44
53
  jkf = ki2_parser.parse(ki2_str) #=> Hash
@@ -46,16 +55,20 @@ jkf = csa_parser.parse(csa_str) #=> Hash
46
55
  ```
47
56
 
48
57
  ```ruby
49
- kif = kif_converter.parse(jkf) #=> String
50
- ki2 = ki2_converter.parse(jkf) #=> String
51
- csa = csa_converter.parse(jkf) #=> String
58
+ kif = kif_converter.convert(jkf) #=> String
59
+ ki2 = ki2_converter.convert(jkf) #=> String
60
+ csa = csa_converter.convert(jkf) #=> String
52
61
  ```
53
62
 
54
63
  ## Contributing
55
64
 
56
- Bug reports and pull requests are welcome on GitHub at https://github.com/iyuuya/jkf.
65
+ Feel free to report bugs or send pull requests at
66
+ [GitHub](https://github.com/iyuuya/jkf).
67
+
68
+ If you work on Guix, run tests by `guix shell`.
57
69
 
58
70
  ## License
59
71
 
60
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
72
+ This gem is licensed under the [MIT
73
+ License](http://opensource.org/licenses/MIT).
61
74
 
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # Jkf
2
- [![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) [![Code Climate](https://codeclimate.com/github/iyuuya/jkf/badges/gpa.svg)](https://codeclimate.com/github/iyuuya/jkf) [![Test Coverage](https://codeclimate.com/github/iyuuya/jkf/badges/coverage.svg)](https://codeclimate.com/github/iyuuya/jkf/coverage) [![Inline docs](http://inch-ci.org/github/iyuuya/jkf.svg?branch=develop)](http://inch-ci.org/github/iyuuya/jkf)
2
+ [![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
3
 
4
- jkfはJSON棋譜フォーマット( https://github.com/na2hiro/json-kifu-format )をRubyに移植したものです。
4
+ jkfは[JSON棋譜フォーマット (JKF)][jkf]をRubyに移植したものです。
5
5
  KIF, KI2, CSAをパースしJKFへ変換、JKFからKIF, KI2, CSAへの変換に対応しています。
6
6
 
7
+ [jkf]: https://github.com/na2hiro/Kifu-for-JS/tree/master/packages/json-kifu-format
8
+
7
9
  ## Installation
8
10
 
9
11
  アプリケーションにインストールする場合(bundlerを使用する場合)、Gemfileに以下のように記述してください。
@@ -45,9 +47,9 @@ jkf = csa_parser.parse(csa_str) #=> Hash
45
47
  ```
46
48
 
47
49
  ```ruby
48
- kif = kif_converter.parse(jkf) #=> String
49
- ki2 = ki2_converter.parse(jkf) #=> String
50
- csa = csa_converter.parse(jkf) #=> String
50
+ kif = kif_converter.convert(jkf) #=> String
51
+ ki2 = ki2_converter.convert(jkf) #=> String
52
+ csa = csa_converter.convert(jkf) #=> String
51
53
  ```
52
54
 
53
55
  ## Contributing
@@ -55,6 +57,8 @@ csa = csa_converter.parse(jkf) #=> String
55
57
  バグレポートやプルリクエストはGithubでよろしくお願いします。
56
58
  https://github.com/iyuuya/jkf.
57
59
 
60
+ Guixで開発されている場合は`guix shell`で`rake test`によるテスト実行ができます。
61
+
58
62
  ## License
59
63
 
60
64
  ライセンスはMITです。
data/Rakefile CHANGED
@@ -1,6 +1,11 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task default: :spec
7
+
8
+ desc 'translate documents'
9
+ task :translate do
10
+ sh 'po4a po4a.cfg'
11
+ end
data/bench.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'benchmark/ips'
2
+ require_relative 'lib/jkf'
3
+
4
+ Benchmark.ips do |x|
5
+ x.report("parse") do
6
+ Dir['spec/*fixtures/**/*'].each do |file|
7
+ Jkf.parse_file(file)
8
+ rescue Jkf::FileTypeError, Jkf::Parser::ParseError
9
+ # okay
10
+ end
11
+ end
12
+ end
data/bin/console CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "jkf"
3
+ require 'bundler/setup'
4
+ require 'jkf'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- if require "pry"
10
+ if require 'pry'
11
11
  Pry.start
12
12
  else
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
15
15
  end
data/jkf.gemspec CHANGED
@@ -1,21 +1,23 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "jkf/version"
3
+ require 'jkf/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "jkf"
6
+ spec.name = 'jkf'
8
7
  spec.version = Jkf::VERSION
9
- spec.authors = ["iyuuya"]
10
- spec.email = ["i.yuuya@gmail.com"]
8
+ spec.authors = ['iyuuya']
9
+ spec.email = ['i.yuuya@gmail.com']
11
10
 
12
- spec.summary = "jkf/csa/kif/ki2 parser and converter"
13
- spec.description = "converter/parser of records of shogi"
14
- spec.homepage = "https://github.com/iyuuya/jkf"
15
- spec.license = "MIT"
11
+ spec.summary = 'jkf/csa/kif/ki2 parser and converter'
12
+ spec.description = 'converter/parser of records of shogi'
13
+ spec.homepage = 'https://github.com/iyuuya/jkf'
14
+ spec.license = 'MIT'
15
+
16
+ spec.required_ruby_version = '>= 3.0'
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
+ spec.bindir = 'exe'
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
21
23
  end
@@ -1,13 +1,15 @@
1
- module Jkf::Converter
2
- # Base of Converter
3
- class Base
4
- # start convert
5
- #
6
- # @param [String, Hash] jkf
7
- # @return [String] kif or ki2 or csa text
8
- def convert(jkf)
9
- jkf = jkf.is_a?(Hash) ? jkf : JSON.parse(jkf)
10
- convert_root(jkf)
1
+ module Jkf
2
+ module Converter
3
+ # Base of Converter
4
+ class Base
5
+ # start convert
6
+ #
7
+ # @param [String, Hash] jkf
8
+ # @return [String] kif or ki2 or csa text
9
+ def convert(jkf)
10
+ jkf = jkf.is_a?(Hash) ? jkf : JSON.parse(jkf)
11
+ convert_root(jkf)
12
+ end
11
13
  end
12
14
  end
13
15
  end