sashite-pan 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e063831fd8f910bd4ad5fd11d708be1bd0afc801b44d00e56934ac083996f34
4
- data.tar.gz: f86d2d6b9fc44f15e9ef9cd5bb09518bea27f6e34644ad74fd11eabce05347aa
3
+ metadata.gz: 4294266795d470a55b2b4d52b1b07e006791ace8a41491473057f839112a8f7d
4
+ data.tar.gz: 30063832b6dba93e56ef2c4450581a3a4f24c1e13592b55576b7a391cbfd23fa
5
5
  SHA512:
6
- metadata.gz: 5aa2c4c4387486061b7d5ef452292fd75067775405b068b127efc27aaf703bb2cf9b1d817f662c8b2076ddd9bf9f14ed605421a3c0f9cd14146529574d308a72
7
- data.tar.gz: 634cdd1a259a459d93b4c3a2eab9db96b30c220f5c320604c6b00dc729634ce69f697c448c0748d05c9d785802007efd6ac4c9db9a60c4008f6d236e1f404fb2
6
+ metadata.gz: 44ce213800f73cfd3094eb4f0d7f52090dae9a229c533827e2c2840cde605fefd2b515c8839277f85c3e4ee67b4d73245f026aa1810111e55cf739e4689c9ee1
7
+ data.tar.gz: 8b97bf4eaec6b839ebfb551bce73341033bcfa3702d6b6c01945355aab3d1857d661e48c5a4ea3783fac8540f4537189e0eb4dfb029812373314a473066275c0
data/README.md CHANGED
@@ -20,52 +20,51 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Working with PMN can be very simple, for example:
23
+ Working with PAN can be very simple, for example:
24
24
 
25
25
  ```ruby
26
26
  require 'sashite/pan'
27
- ```
28
27
 
29
- ### King's Pawn opening at chess
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
30
37
 
31
- ```ruby
32
38
  Sashite::PAN.parse('52,36,♙') # => [[52, 36, '♙', nil]]
33
- Sashite::PAN.dump([52, 36, '♙', nil]) # => '52,36,♙'
34
39
  ```
35
40
 
36
- ### Black castles on king-side
41
+ ## Examples
37
42
 
38
43
  ```ruby
39
- Sashite::PAN.parse('60,62,♔;63,61,♖') # => [[60, 62, '♔', nil], [63, 61, '♖', nil]]
44
+ # Black castles on king-side
45
+
40
46
  Sashite::PAN.dump([60, 62, '♔', nil], [63, 61, '♖', nil]) # => '60,62,♔;63,61,♖'
41
- ```
47
+ Sashite::PAN.parse('60,62,♔;63,61,♖') # => [[60, 62, '♔', nil], [63, 61, '♖', nil]]
42
48
 
43
- ### Promoting a chess pawn into a knight
49
+ # Promoting a chess pawn into a knight
44
50
 
45
- ```ruby
46
- Sashite::PAN.parse('12,4,♘') # => [[12, 4, '♘', nil]]
47
51
  Sashite::PAN.dump([12, 4, '♘', nil]) # => '12,4,♘'
48
- ```
52
+ Sashite::PAN.parse('12,4,♘') # => [[12, 4, '♘', nil]]
49
53
 
50
- ### Capturing a rook and promoting a shogi pawn
54
+ # Capturing a rook and promoting a shogi pawn
51
55
 
52
- ```ruby
53
- Sashite::PAN.parse('33,24,+P,R') # => [[33, 24, '+P', 'R']]
54
56
  Sashite::PAN.dump([33, 24, '+P', 'R']) # => '33,24,+P,R'
55
- ```
57
+ Sashite::PAN.parse('33,24,+P,R') # => [[33, 24, '+P', 'R']]
56
58
 
57
- ### Dropping a shogi pawn
59
+ # Dropping a shogi pawn
58
60
 
59
- ```ruby
60
- Sashite::PAN.parse('*,42,P') # => [[nil, 42, 'P', nil]]
61
61
  Sashite::PAN.dump([nil, 42, 'P', nil]) # => '*,42,P'
62
- ```
62
+ Sashite::PAN.parse('*,42,P') # => [[nil, 42, 'P', nil]]
63
63
 
64
- ### Capturing a white chess pawn _en passant_
64
+ # Capturing a white chess pawn en passant
65
65
 
66
- ```ruby
67
- Sashite::PAN.parse('33,32,♟;32,40,♟') # => [[33, 32, '♟', nil], [32, 40, '♟', nil]]
68
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]]
69
68
  ```
70
69
 
71
70
  ## License
@@ -0,0 +1,10 @@
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
+ end
9
+ end
10
+ end
@@ -1,25 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'action'
4
+
3
5
  module Sashite
4
6
  module PAN
5
7
  # Dumper class
6
- class Dumper
7
- def self.call(*unserialized_actions)
8
- unserialized_actions.map { |params| new(*params).call }.join(';')
8
+ class Dumper < Action
9
+ def self.call(*actions)
10
+ actions.map { |action_items| new(*action_items).call }.join(';')
9
11
  end
10
12
 
11
- attr_reader :src_square, :dst_square, :piece_name, :piece_hand
12
-
13
13
  def initialize(src_square, dst_square, piece_name, piece_hand)
14
14
  unless src_square.nil?
15
- raise src_square.inspect unless src_square.is_a?(Integer)
15
+ raise TypeError, src_square.inspect unless src_square.is_a?(Integer)
16
16
  end
17
17
 
18
- raise dst_square.inspect unless dst_square.is_a?(Integer)
19
- raise piece_name.inspect unless piece_name.is_a?(String)
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
20
 
21
21
  unless piece_hand.nil?
22
- raise piece_hand.inspect unless piece_hand.is_a?(String)
22
+ raise TypeError, piece_hand.inspect unless piece_hand.is_a?(String)
23
23
  end
24
24
 
25
25
  @src_square = (src_square.nil? ? '*' : src_square)
@@ -1,31 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'action'
4
+
3
5
  module Sashite
4
6
  module PAN
5
7
  # Parser class
6
- class Parser
7
- def self.call(serialized_actions)
8
- serialized_actions.split(';').map do |serialized_action|
8
+ class Parser < Action
9
+ def self.call(pan_string)
10
+ pan_string.split(';').map do |serialized_action|
9
11
  new(serialized_action).call
10
12
  end
11
13
  end
12
14
 
13
- attr_reader :serialized_action
14
-
15
15
  def initialize(serialized_action)
16
- @serialized_action = serialized_action
16
+ action_args = serialized_action.split(',')
17
+ src_square = action_args.fetch(0)
18
+ @src_square = src_square.eql?('*') ? nil : src_square.to_i
19
+ @dst_square = action_args.fetch(1).to_i
20
+ @piece_name = action_args.fetch(2)
21
+ @piece_hand = action_args.fetch(3, nil)
17
22
  end
18
23
 
19
24
  def call
20
- action_args = serialized_action.split(',')
21
-
22
- src_square = action_args.fetch(0)
23
- src_square = src_square.eql?('*') ? nil : src_square.to_i
24
- dst_square = action_args.fetch(1).to_i
25
- piece_name = action_args.fetch(2)
26
- piece_hand = action_args.fetch(3, nil)
27
-
28
- [src_square, dst_square, piece_name, piece_hand]
25
+ [
26
+ src_square,
27
+ dst_square,
28
+ piece_name,
29
+ piece_hand
30
+ ]
29
31
  end
30
32
  end
31
33
  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.0.0
4
+ version: 1.1.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-06-16 00:00:00.000000000 Z
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -133,6 +133,7 @@ files:
133
133
  - README.md
134
134
  - lib/sashite-pan.rb
135
135
  - lib/sashite/pan.rb
136
+ - lib/sashite/pan/action.rb
136
137
  - lib/sashite/pan/dumper.rb
137
138
  - lib/sashite/pan/parser.rb
138
139
  homepage: https://developer.sashite.com/specs/portable-action-notation