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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4294266795d470a55b2b4d52b1b07e006791ace8a41491473057f839112a8f7d
4
- data.tar.gz: 30063832b6dba93e56ef2c4450581a3a4f24c1e13592b55576b7a391cbfd23fa
3
+ metadata.gz: ddc5404d30aecb881216eeeda12f98c7295f8dd415302f343c8ac0d0434a7289
4
+ data.tar.gz: a70d32986e8e6c1f90dedd8039562089e1f40b8c64a4dcfb518f0bfdd0592904
5
5
  SHA512:
6
- metadata.gz: 44ce213800f73cfd3094eb4f0d7f52090dae9a229c533827e2c2840cde605fefd2b515c8839277f85c3e4ee67b4d73245f026aa1810111e55cf739e4689c9ee1
7
- data.tar.gz: 8b97bf4eaec6b839ebfb551bce73341033bcfa3702d6b6c01945355aab3d1857d661e48c5a4ea3783fac8540f4537189e0eb4dfb029812373314a473066275c0
6
+ metadata.gz: f1ec2c07c1e3ecfbd9dde636595c182178891217eeea5c2724c994b8e8010f2d8ae371e48a5399ef3682ef22b6f9c35550a83123b0e2035dd0603a00c1cf101c
7
+ data.tar.gz: ca173e3c7ecd0e49e9026a1f8b5ae9b7f8375c7d893e45b20b8ca7723e10dfe8701f4b4ef837414f2436014653b2accc2a9d2fb2b9b71cf9307c88d4840b745b
@@ -7,8 +7,8 @@ module Sashite
7
7
  Dumper.call(*actions)
8
8
  end
9
9
 
10
- def self.parse(pan_string)
11
- Parser.call(pan_string)
10
+ def self.parse(string)
11
+ Parser.call(string)
12
12
  end
13
13
  end
14
14
  end
@@ -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
@@ -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 }.join(';')
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
- unless src_square.nil?
15
- raise TypeError, src_square.inspect unless src_square.is_a?(Integer)
16
- end
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
@@ -6,28 +6,22 @@ module Sashite
6
6
  module PAN
7
7
  # Parser class
8
8
  class Parser < Action
9
- def self.call(pan_string)
10
- pan_string.split(';').map do |serialized_action|
11
- new(serialized_action).call
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?('*') ? nil : src_square.to_i
19
- @dst_square = action_args.fetch(1).to_i
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.1.0
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-06-19 00:00:00.000000000 Z
11
+ date: 2020-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print