sashite-pan 0.0.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE.md +1 -1
- data/README.md +59 -19
- data/lib/sashite-pan.rb +6 -1
- data/lib/sashite/pan.rb +10 -27
- data/lib/sashite/pan/action.rb +24 -0
- data/lib/sashite/pan/dumper.rb +34 -0
- data/lib/sashite/pan/parser.rb +28 -0
- metadata +100 -56
- data/.gitignore +0 -22
- data/.ruby-version +0 -1
- data/.travis.yml +0 -3
- data/Gemfile +0 -2
- data/Rakefile +0 -7
- data/VERSION.semver +0 -1
- data/lib/sashite/pan/capture.rb +0 -24
- data/lib/sashite/pan/drop.rb +0 -23
- data/lib/sashite/pan/error/not_implemented_verb_error.rb +0 -6
- data/lib/sashite/pan/error/same_square_error.rb +0 -6
- data/lib/sashite/pan/promote.rb +0 -23
- data/lib/sashite/pan/remove.rb +0 -24
- data/lib/sashite/pan/shift.rb +0 -24
- data/sashite-pan.gemspec +0 -19
- data/test/_test_helper.rb +0 -2
- data/test/test_capture.rb +0 -41
- data/test/test_drop.rb +0 -37
- data/test/test_movement.rb.rb +0 -9
- data/test/test_pan.rb +0 -9
- data/test/test_promote.rb +0 -37
- data/test/test_remove.rb +0 -41
- data/test/test_shift.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ddc5404d30aecb881216eeeda12f98c7295f8dd415302f343c8ac0d0434a7289
|
4
|
+
data.tar.gz: a70d32986e8e6c1f90dedd8039562089e1f40b8c64a4dcfb518f0bfdd0592904
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1ec2c07c1e3ecfbd9dde636595c182178891217eeea5c2724c994b8e8010f2d8ae371e48a5399ef3682ef22b6f9c35550a83123b0e2035dd0603a00c1cf101c
|
7
|
+
data.tar.gz: ca173e3c7ecd0e49e9026a1f8b5ae9b7f8375c7d893e45b20b8ca7723e10dfe8701f4b4ef837414f2436014653b2accc2a9d2fb2b9b71cf9307c88d4840b745b
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,18 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# Portable Action Notation
|
2
2
|
|
3
|
-
Ruby
|
4
|
-
|
5
|
-
## Status
|
6
|
-
|
7
|
-
* [![Gem Version](https://badge.fury.io/rb/sashite-pan.svg)](//badge.fury.io/rb/sashite-pan)
|
8
|
-
* [![Build Status](https://secure.travis-ci.org/sashite/pan.rb.svg?branch=master)](//travis-ci.org/sashite/pan.rb?branch=master)
|
9
|
-
* [![Dependency Status](https://gemnasium.com/sashite/pan.rb.svg)](//gemnasium.com/sashite/pan.rb)
|
3
|
+
A Ruby interface for data serialization in [PAN](https://developer.sashite.com/specs/portable-action-notation) format.
|
10
4
|
|
11
5
|
## Installation
|
12
6
|
|
13
7
|
Add this line to your application's Gemfile:
|
14
8
|
|
15
|
-
|
9
|
+
```ruby
|
10
|
+
gem 'sashite-pan'
|
11
|
+
```
|
16
12
|
|
17
13
|
And then execute:
|
18
14
|
|
@@ -22,17 +18,61 @@ Or install it yourself as:
|
|
22
18
|
|
23
19
|
$ gem install sashite-pan
|
24
20
|
|
25
|
-
##
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Working with PAN can be very simple, for example:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'sashite/pan'
|
27
|
+
|
28
|
+
# Emit a PAN string
|
29
|
+
|
30
|
+
actions = [
|
31
|
+
[52, 36, '♙', nil]
|
32
|
+
]
|
33
|
+
|
34
|
+
Sashite::PAN.dump(*actions) # => '52,36,♙'
|
35
|
+
|
36
|
+
# Parse a PAN string
|
37
|
+
|
38
|
+
Sashite::PAN.parse('52,36,♙') # => [[52, 36, '♙', nil]]
|
39
|
+
```
|
40
|
+
|
41
|
+
## Examples
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
# Black castles on king-side
|
45
|
+
|
46
|
+
Sashite::PAN.dump([60, 62, '♔', nil], [63, 61, '♖', nil]) # => '60,62,♔;63,61,♖'
|
47
|
+
Sashite::PAN.parse('60,62,♔;63,61,♖') # => [[60, 62, '♔', nil], [63, 61, '♖', nil]]
|
48
|
+
|
49
|
+
# Promoting a chess pawn into a knight
|
50
|
+
|
51
|
+
Sashite::PAN.dump([12, 4, '♘', nil]) # => '12,4,♘'
|
52
|
+
Sashite::PAN.parse('12,4,♘') # => [[12, 4, '♘', nil]]
|
53
|
+
|
54
|
+
# Capturing a rook and promoting a shogi pawn
|
55
|
+
|
56
|
+
Sashite::PAN.dump([33, 24, '+P', 'R']) # => '33,24,+P,R'
|
57
|
+
Sashite::PAN.parse('33,24,+P,R') # => [[33, 24, '+P', 'R']]
|
58
|
+
|
59
|
+
# Dropping a shogi pawn
|
60
|
+
|
61
|
+
Sashite::PAN.dump([nil, 42, 'P', nil]) # => '*,42,P'
|
62
|
+
Sashite::PAN.parse('*,42,P') # => [[nil, 42, 'P', nil]]
|
63
|
+
|
64
|
+
# Capturing a white chess pawn en passant
|
65
|
+
|
66
|
+
Sashite::PAN.dump([33, 32, '♟', nil], [32, 40, '♟', nil]) # => '33,32,♟;32,40,♟'
|
67
|
+
Sashite::PAN.parse('33,32,♟;32,40,♟') # => [[33, 32, '♟', nil], [32, 40, '♟', nil]]
|
68
|
+
```
|
69
|
+
|
70
|
+
## License
|
26
71
|
|
27
|
-
|
72
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
28
73
|
|
29
|
-
|
30
|
-
action.src_square # => 42
|
74
|
+
## About Sashite
|
31
75
|
|
32
|
-
|
76
|
+
The `sashite-pan` gem is maintained by [Sashite](https://sashite.com/).
|
33
77
|
|
34
|
-
|
35
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
-
5. Create new Pull Request
|
78
|
+
With some [lines of code](https://github.com/sashite/), let's share the beauty of Chinese, Japanese and Western cultures through the game of chess!
|
data/lib/sashite-pan.rb
CHANGED
data/lib/sashite/pan.rb
CHANGED
@@ -1,34 +1,17 @@
|
|
1
|
-
|
2
|
-
require_relative 'pan/drop'
|
3
|
-
require_relative 'pan/error/not_implemented_verb_error'
|
4
|
-
require_relative 'pan/error/same_square_error'
|
5
|
-
require_relative 'pan/promote'
|
6
|
-
require_relative 'pan/remove'
|
7
|
-
require_relative 'pan/shift'
|
1
|
+
# frozen_string_literal: true
|
8
2
|
|
9
3
|
module Sashite
|
4
|
+
# The PAN (Portable Action Notation) module
|
10
5
|
module PAN
|
11
|
-
def self.
|
12
|
-
|
13
|
-
|
14
|
-
when :capture
|
15
|
-
Capture.new arg1, arg2
|
16
|
-
|
17
|
-
when :drop
|
18
|
-
Drop.new arg1, arg2
|
19
|
-
|
20
|
-
when :promote
|
21
|
-
Promote.new arg1, arg2
|
22
|
-
|
23
|
-
when :remove
|
24
|
-
Remove.new arg1, arg2
|
25
|
-
|
26
|
-
when :shift
|
27
|
-
Shift.new arg1, arg2
|
6
|
+
def self.dump(*actions)
|
7
|
+
Dumper.call(*actions)
|
8
|
+
end
|
28
9
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
10
|
+
def self.parse(string)
|
11
|
+
Parser.call(string)
|
32
12
|
end
|
33
13
|
end
|
34
14
|
end
|
15
|
+
|
16
|
+
require_relative 'pan/dumper'
|
17
|
+
require_relative 'pan/parser'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sashite
|
4
|
+
module PAN
|
5
|
+
# Action class
|
6
|
+
class Action
|
7
|
+
attr_reader :src_square, :dst_square, :piece_name, :piece_hand
|
8
|
+
|
9
|
+
private_class_method def self.separator
|
10
|
+
';'
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def separator
|
16
|
+
','
|
17
|
+
end
|
18
|
+
|
19
|
+
def drop_char
|
20
|
+
'*'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'action'
|
4
|
+
|
5
|
+
module Sashite
|
6
|
+
module PAN
|
7
|
+
# Dumper class
|
8
|
+
class Dumper < Action
|
9
|
+
def self.call(*actions)
|
10
|
+
actions.map { |action_items| new(*action_items).call }
|
11
|
+
.join(separator)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(src_square, dst_square, piece_name, piece_hand)
|
15
|
+
@src_square = src_square.nil? ? drop_char : Integer(src_square)
|
16
|
+
@dst_square = Integer(dst_square)
|
17
|
+
@piece_name = piece_name.to_s
|
18
|
+
@piece_hand = piece_hand&.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
action_items.join(separator)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def action_items
|
28
|
+
return [src_square, dst_square, piece_name] if piece_hand.nil?
|
29
|
+
|
30
|
+
[src_square, dst_square, piece_name, piece_hand]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'action'
|
4
|
+
|
5
|
+
module Sashite
|
6
|
+
module PAN
|
7
|
+
# Parser class
|
8
|
+
class Parser < Action
|
9
|
+
def self.call(serialized_move)
|
10
|
+
serialized_move.split(separator)
|
11
|
+
.map { |serialized_action| new(serialized_action).call }
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(serialized_action)
|
15
|
+
action_args = serialized_action.split(separator)
|
16
|
+
src_square = action_args.fetch(0)
|
17
|
+
@src_square = src_square.eql?(drop_char) ? nil : Integer(src_square)
|
18
|
+
@dst_square = Integer(action_args.fetch(1))
|
19
|
+
@piece_name = action_args.fetch(2)
|
20
|
+
@piece_hand = action_args.fetch(3, nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
def call
|
24
|
+
[src_square, dst_square, piece_name, piece_hand]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,95 +1,148 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sashite-pan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Cyril
|
7
|
+
- Cyril Kato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: awesome_print
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- - "
|
31
|
+
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
33
|
+
version: '0'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- - "
|
38
|
+
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: byebug
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-performance
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-thread_safety
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: yard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
46
116
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
117
|
+
version: '0'
|
48
118
|
type: :development
|
49
119
|
prerelease: false
|
50
120
|
version_requirements: !ruby/object:Gem::Requirement
|
51
121
|
requirements:
|
52
|
-
- - "
|
122
|
+
- - ">="
|
53
123
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
description: A
|
56
|
-
|
57
|
-
email:
|
58
|
-
- contact@cyril.io
|
124
|
+
version: '0'
|
125
|
+
description: A Ruby interface for data serialization in PAN (Portable Action Notation)
|
126
|
+
format.
|
127
|
+
email: contact@cyril.email
|
59
128
|
executables: []
|
60
129
|
extensions: []
|
61
130
|
extra_rdoc_files: []
|
62
131
|
files:
|
63
|
-
- ".gitignore"
|
64
|
-
- ".ruby-version"
|
65
|
-
- ".travis.yml"
|
66
|
-
- Gemfile
|
67
132
|
- LICENSE.md
|
68
133
|
- README.md
|
69
|
-
- Rakefile
|
70
|
-
- VERSION.semver
|
71
134
|
- lib/sashite-pan.rb
|
72
135
|
- lib/sashite/pan.rb
|
73
|
-
- lib/sashite/pan/
|
74
|
-
- lib/sashite/pan/
|
75
|
-
- lib/sashite/pan/
|
76
|
-
|
77
|
-
- lib/sashite/pan/promote.rb
|
78
|
-
- lib/sashite/pan/remove.rb
|
79
|
-
- lib/sashite/pan/shift.rb
|
80
|
-
- sashite-pan.gemspec
|
81
|
-
- test/_test_helper.rb
|
82
|
-
- test/test_capture.rb
|
83
|
-
- test/test_drop.rb
|
84
|
-
- test/test_movement.rb.rb
|
85
|
-
- test/test_pan.rb
|
86
|
-
- test/test_promote.rb
|
87
|
-
- test/test_remove.rb
|
88
|
-
- test/test_shift.rb
|
89
|
-
homepage: https://github.com/sashite/pan.rb
|
136
|
+
- lib/sashite/pan/action.rb
|
137
|
+
- lib/sashite/pan/dumper.rb
|
138
|
+
- lib/sashite/pan/parser.rb
|
139
|
+
homepage: https://developer.sashite.com/specs/portable-action-notation
|
90
140
|
licenses:
|
91
141
|
- MIT
|
92
|
-
metadata:
|
142
|
+
metadata:
|
143
|
+
bug_tracker_uri: https://github.com/sashite/pan.rb/issues
|
144
|
+
documentation_uri: https://rubydoc.info/gems/sashite-pan/index
|
145
|
+
source_code_uri: https://github.com/sashite/pan.rb
|
93
146
|
post_install_message:
|
94
147
|
rdoc_options: []
|
95
148
|
require_paths:
|
@@ -105,17 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
158
|
- !ruby/object:Gem::Version
|
106
159
|
version: '0'
|
107
160
|
requirements: []
|
108
|
-
|
109
|
-
rubygems_version: 2.2.2
|
161
|
+
rubygems_version: 3.1.2
|
110
162
|
signing_key:
|
111
163
|
specification_version: 4
|
112
|
-
summary:
|
113
|
-
test_files:
|
114
|
-
- test/_test_helper.rb
|
115
|
-
- test/test_capture.rb
|
116
|
-
- test/test_drop.rb
|
117
|
-
- test/test_movement.rb.rb
|
118
|
-
- test/test_pan.rb
|
119
|
-
- test/test_promote.rb
|
120
|
-
- test/test_remove.rb
|
121
|
-
- test/test_shift.rb
|
164
|
+
summary: Data serialization in PAN format.
|
165
|
+
test_files: []
|
data/.gitignore
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
*.bundle
|
19
|
-
*.so
|
20
|
-
*.o
|
21
|
-
*.a
|
22
|
-
mkmf.log
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1.2
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/VERSION.semver
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.2
|
data/lib/sashite/pan/capture.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Sashite
|
2
|
-
module PAN
|
3
|
-
class Capture
|
4
|
-
attr_reader :src_square, :dst_square
|
5
|
-
|
6
|
-
def initialize src_square, dst_square
|
7
|
-
raise TypeError unless src_square.is_a? Fixnum
|
8
|
-
raise TypeError unless dst_square.is_a? Fixnum
|
9
|
-
raise SameSquareError if src_square == dst_square
|
10
|
-
|
11
|
-
@src_square = src_square
|
12
|
-
@dst_square = dst_square
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_a
|
16
|
-
[
|
17
|
-
self.class.name.split('::').last.downcase.to_sym,
|
18
|
-
@src_square,
|
19
|
-
@dst_square
|
20
|
-
]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/sashite/pan/drop.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Sashite
|
2
|
-
module PAN
|
3
|
-
class Drop
|
4
|
-
attr_reader :actor, :dst_square
|
5
|
-
|
6
|
-
def initialize actor, dst_square
|
7
|
-
raise TypeError unless actor.is_a? Symbol
|
8
|
-
raise TypeError unless dst_square.is_a? Fixnum
|
9
|
-
|
10
|
-
@actor = actor
|
11
|
-
@dst_square = dst_square
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_a
|
15
|
-
[
|
16
|
-
self.class.name.split('::').last.downcase.to_sym,
|
17
|
-
@actor,
|
18
|
-
@dst_square
|
19
|
-
]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/sashite/pan/promote.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Sashite
|
2
|
-
module PAN
|
3
|
-
class Promote
|
4
|
-
attr_reader :src_square, :actor
|
5
|
-
|
6
|
-
def initialize src_square, actor
|
7
|
-
raise TypeError unless src_square.is_a? Fixnum
|
8
|
-
raise TypeError unless actor.is_a? Symbol
|
9
|
-
|
10
|
-
@src_square = src_square
|
11
|
-
@actor = actor
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_a
|
15
|
-
[
|
16
|
-
self.class.name.split('::').last.downcase.to_sym,
|
17
|
-
@src_square,
|
18
|
-
@actor
|
19
|
-
]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/sashite/pan/remove.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Sashite
|
2
|
-
module PAN
|
3
|
-
class Remove
|
4
|
-
attr_reader :src_square, :dst_square
|
5
|
-
|
6
|
-
def initialize src_square, dst_square
|
7
|
-
raise TypeError unless src_square.is_a? Fixnum
|
8
|
-
raise TypeError unless dst_square.is_a? Fixnum
|
9
|
-
raise SameSquareError if src_square == dst_square
|
10
|
-
|
11
|
-
@src_square = src_square
|
12
|
-
@dst_square = dst_square
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_a
|
16
|
-
[
|
17
|
-
self.class.name.split('::').last.downcase.to_sym,
|
18
|
-
@src_square,
|
19
|
-
@dst_square
|
20
|
-
]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/sashite/pan/shift.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Sashite
|
2
|
-
module PAN
|
3
|
-
class Shift
|
4
|
-
attr_reader :src_square, :dst_square
|
5
|
-
|
6
|
-
def initialize src_square, dst_square
|
7
|
-
raise TypeError unless src_square.is_a? Fixnum
|
8
|
-
raise TypeError unless dst_square.is_a? Fixnum
|
9
|
-
raise SameSquareError if src_square == dst_square
|
10
|
-
|
11
|
-
@src_square = src_square
|
12
|
-
@dst_square = dst_square
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_a
|
16
|
-
[
|
17
|
-
self.class.name.split('::').last.downcase.to_sym,
|
18
|
-
@src_square,
|
19
|
-
@dst_square
|
20
|
-
]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/sashite-pan.gemspec
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |spec|
|
2
|
-
spec.name = 'sashite-pan'
|
3
|
-
spec.version = File.read('VERSION.semver')
|
4
|
-
spec.authors = ['Cyril Wack']
|
5
|
-
spec.email = ['contact@cyril.io']
|
6
|
-
spec.summary = %q{Portable Action Notation (PAN) parser and emitter.}
|
7
|
-
spec.description = %q{A Portable Action Notation (PAN) parser and emitter, optimized for programmer happiness.}
|
8
|
-
spec.homepage = 'https://github.com/sashite/pan.rb'
|
9
|
-
spec.license = 'MIT'
|
10
|
-
|
11
|
-
spec.files = `git ls-files -z`.split("\x0")
|
12
|
-
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
|
13
|
-
spec.test_files = spec.files.grep(%r{^test/})
|
14
|
-
spec.require_paths = ['lib']
|
15
|
-
|
16
|
-
spec.add_development_dependency 'bundler', '~> 1.6'
|
17
|
-
spec.add_development_dependency 'minitest', '~> 5'
|
18
|
-
spec.add_development_dependency 'rake', '~> 10'
|
19
|
-
end
|
data/test/_test_helper.rb
DELETED
data/test/test_capture.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require_relative '_test_helper'
|
2
|
-
|
3
|
-
describe Sashite::PAN do
|
4
|
-
describe 'capture' do
|
5
|
-
describe 'errors' do
|
6
|
-
it 'raises a same square error' do
|
7
|
-
-> { Sashite::PAN::Capture.new 42, 42 }.must_raise Sashite::PAN::SameSquareError
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'raises a type error from the source square' do
|
11
|
-
-> { Sashite::PAN::Capture.new '42', 43 }.must_raise TypeError
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'raises a type error from the destination square' do
|
15
|
-
-> { Sashite::PAN::Capture.new 42, '43' }.must_raise TypeError
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'instances' do
|
20
|
-
before do
|
21
|
-
@action = Sashite::PAN.load :capture, 42, 43
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns the action' do
|
25
|
-
@action.to_a.must_equal [ :capture, 42, 43 ]
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'returns the action (once again)' do
|
29
|
-
@action.to_a.must_equal Sashite::PAN::Capture.new(42, 43).to_a
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns the src_square of the action' do
|
33
|
-
@action.src_square.must_equal 42
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns the dst_square of the action' do
|
37
|
-
@action.dst_square.must_equal 43
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/test/test_drop.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require_relative '_test_helper'
|
2
|
-
|
3
|
-
describe Sashite::PAN do
|
4
|
-
describe 'drops' do
|
5
|
-
describe 'errors' do
|
6
|
-
it 'raises a type error from the actor' do
|
7
|
-
-> { Sashite::PAN.load :drop, 'foobar', 42 }.must_raise TypeError
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'raises a type error from the destination square' do
|
11
|
-
-> { Sashite::PAN.load :drop, :foobar, '42' }.must_raise TypeError
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'instances' do
|
16
|
-
before do
|
17
|
-
@action = Sashite::PAN.load :drop, :foobar, 42
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns the action' do
|
21
|
-
@action.to_a.must_equal [ :drop, :foobar, 42 ]
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns the action (once again)' do
|
25
|
-
@action.to_a.must_equal Sashite::PAN::Drop.new(:foobar, 42).to_a
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'returns the actor of the action' do
|
29
|
-
@action.actor.must_equal :foobar
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns the dst_square of the action' do
|
33
|
-
@action.dst_square.must_equal 42
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/test/test_movement.rb.rb
DELETED
data/test/test_pan.rb
DELETED
data/test/test_promote.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require_relative '_test_helper'
|
2
|
-
|
3
|
-
describe Sashite::PAN do
|
4
|
-
describe 'promotion' do
|
5
|
-
describe 'errors' do
|
6
|
-
it 'raises a type error from the source square' do
|
7
|
-
-> { Sashite::PAN.load :promote, '42', :foobar }.must_raise TypeError
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'raises a type error from the actor' do
|
11
|
-
-> { Sashite::PAN.load :promote, 42, 'foobar' }.must_raise TypeError
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'instances' do
|
16
|
-
before do
|
17
|
-
@action = Sashite::PAN.load :promote, 42, :foobar
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns the action' do
|
21
|
-
@action.to_a.must_equal [ :promote, 42, :foobar ]
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns the action (once again)' do
|
25
|
-
@action.to_a.must_equal Sashite::PAN::Promote.new(42, :foobar).to_a
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'returns the src_square of the action' do
|
29
|
-
@action.src_square.must_equal 42
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns the actor of the action' do
|
33
|
-
@action.actor.must_equal :foobar
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/test/test_remove.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require_relative '_test_helper'
|
2
|
-
|
3
|
-
describe Sashite::PAN do
|
4
|
-
describe 'remove' do
|
5
|
-
describe 'errors' do
|
6
|
-
it 'raises a same square error' do
|
7
|
-
-> { Sashite::PAN::Remove.new 42, 42 }.must_raise Sashite::PAN::SameSquareError
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'raises a type error from the source square' do
|
11
|
-
-> { Sashite::PAN::Remove.new '42', 43 }.must_raise TypeError
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'raises a type error from the destination square' do
|
15
|
-
-> { Sashite::PAN::Remove.new 42, '43' }.must_raise TypeError
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'instances' do
|
20
|
-
before do
|
21
|
-
@action = Sashite::PAN.load :remove, 42, 43
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns the action' do
|
25
|
-
@action.to_a.must_equal [ :remove, 42, 43 ]
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'returns the action (once again)' do
|
29
|
-
@action.to_a.must_equal Sashite::PAN::Remove.new(42, 43).to_a
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns the src_square of the action' do
|
33
|
-
@action.src_square.must_equal 42
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns the dst_square of the action' do
|
37
|
-
@action.dst_square.must_equal 43
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/test/test_shift.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require_relative '_test_helper'
|
2
|
-
|
3
|
-
describe Sashite::PAN do
|
4
|
-
describe 'shift' do
|
5
|
-
describe 'errors' do
|
6
|
-
it 'raises a same square error' do
|
7
|
-
-> { Sashite::PAN::Shift.new 42, 42 }.must_raise Sashite::PAN::SameSquareError
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'raises a type error from the source square' do
|
11
|
-
-> { Sashite::PAN::Shift.new '42', 43 }.must_raise TypeError
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'raises a type error from the destination square' do
|
15
|
-
-> { Sashite::PAN::Shift.new 42, '43' }.must_raise TypeError
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'instances' do
|
20
|
-
before do
|
21
|
-
@action = Sashite::PAN.load :shift, 42, 43
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns the action' do
|
25
|
-
@action.to_a.must_equal [ :shift, 42, 43 ]
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'returns the action (once again)' do
|
29
|
-
@action.to_a.must_equal Sashite::PAN::Shift.new(42, 43).to_a
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns the src_square of the action' do
|
33
|
-
@action.src_square.must_equal 42
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns the dst_square of the action' do
|
37
|
-
@action.dst_square.must_equal 43
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|