sashite-pan 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sashite/pan.rb +2 -2
- data/lib/sashite/pan/action.rb +14 -0
- data/lib/sashite/pan/dumper.rb +7 -17
- data/lib/sashite/pan/parser.rb +7 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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/lib/sashite/pan.rb
CHANGED
data/lib/sashite/pan/action.rb
CHANGED
@@ -5,6 +5,20 @@ module Sashite
|
|
5
5
|
# Action class
|
6
6
|
class Action
|
7
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
|
8
22
|
end
|
9
23
|
end
|
10
24
|
end
|
data/lib/sashite/pan/dumper.rb
CHANGED
@@ -7,29 +7,19 @@ module Sashite
|
|
7
7
|
# Dumper class
|
8
8
|
class Dumper < Action
|
9
9
|
def self.call(*actions)
|
10
|
-
actions.map { |action_items| new(*action_items).call }
|
10
|
+
actions.map { |action_items| new(*action_items).call }
|
11
|
+
.join(separator)
|
11
12
|
end
|
12
13
|
|
13
14
|
def initialize(src_square, dst_square, piece_name, piece_hand)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
raise TypeError, dst_square.inspect unless dst_square.is_a?(Integer)
|
19
|
-
raise TypeError, piece_name.inspect unless piece_name.is_a?(String)
|
20
|
-
|
21
|
-
unless piece_hand.nil?
|
22
|
-
raise TypeError, piece_hand.inspect unless piece_hand.is_a?(String)
|
23
|
-
end
|
24
|
-
|
25
|
-
@src_square = (src_square.nil? ? '*' : src_square)
|
26
|
-
@dst_square = dst_square
|
27
|
-
@piece_name = piece_name
|
28
|
-
@piece_hand = 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
|
29
19
|
end
|
30
20
|
|
31
21
|
def call
|
32
|
-
action_items.join(
|
22
|
+
action_items.join(separator)
|
33
23
|
end
|
34
24
|
|
35
25
|
private
|
data/lib/sashite/pan/parser.rb
CHANGED
@@ -6,28 +6,22 @@ module Sashite
|
|
6
6
|
module PAN
|
7
7
|
# Parser class
|
8
8
|
class Parser < Action
|
9
|
-
def self.call(
|
10
|
-
|
11
|
-
|
12
|
-
end
|
9
|
+
def self.call(serialized_move)
|
10
|
+
serialized_move.split(separator)
|
11
|
+
.map { |serialized_action| new(serialized_action).call }
|
13
12
|
end
|
14
13
|
|
15
14
|
def initialize(serialized_action)
|
16
|
-
action_args = serialized_action.split(
|
15
|
+
action_args = serialized_action.split(separator)
|
17
16
|
src_square = action_args.fetch(0)
|
18
|
-
@src_square = src_square.eql?(
|
19
|
-
@dst_square = action_args.fetch(1)
|
17
|
+
@src_square = src_square.eql?(drop_char) ? nil : Integer(src_square)
|
18
|
+
@dst_square = Integer(action_args.fetch(1))
|
20
19
|
@piece_name = action_args.fetch(2)
|
21
20
|
@piece_hand = action_args.fetch(3, nil)
|
22
21
|
end
|
23
22
|
|
24
23
|
def call
|
25
|
-
[
|
26
|
-
src_square,
|
27
|
-
dst_square,
|
28
|
-
piece_name,
|
29
|
-
piece_hand
|
30
|
-
]
|
24
|
+
[src_square, dst_square, piece_name, piece_hand]
|
31
25
|
end
|
32
26
|
end
|
33
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sashite-pan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|