chess_data 1.0.7 → 1.0.8
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/README.rdoc +6 -0
- data/lib/chess_data/database.rb +2 -2
- data/lib/chess_data/game.rb +4 -4
- data/lib/chess_data/moves.rb +1 -1
- data/lib/chess_data/position-definition.rb +2 -2
- data/lib/chess_data/vendor/word_wrap/lib/word_wrap/core_ext.rb +26 -0
- data/lib/chess_data/vendor/word_wrap/lib/word_wrap/version.rb +3 -0
- data/lib/chess_data/vendor/word_wrap/lib/word_wrap/wrapper.rb +97 -0
- data/lib/chess_data/vendor/word_wrap/lib/word_wrap.rb +14 -0
- data/lib/chess_data.rb +8 -6
- metadata +25 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: be0c992c2a1840d2660f10ff3cdcc95975bae14231479d6185f61fcdb39cdf9c
|
|
4
|
+
data.tar.gz: 81f5b14ff8d16a797874742657c0f214325bdfa03a10655d02e917bb9cd9b576
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8465632f6311ef6bf14a457b3c7f0a73df653494a31369ff06e01693972dc737ec66cb603f28d52b79506fe91cdf2f401500c5b1fdc9d7d478863381da2da42c
|
|
7
|
+
data.tar.gz: 3acb47c05323a23d7c18fc1414e8e0a35cbeaf6e862b8e94be0a1d761b0c238fbcd79f9d0b49f77995628213d12654eaf3aedd3463cd172b791374035d92a70d
|
data/README.rdoc
CHANGED
|
@@ -113,3 +113,9 @@ Sample output:
|
|
|
113
113
|
|
|
114
114
|
Move 33: ... 1/2-1/2
|
|
115
115
|
|
|
116
|
+
== Credits and Dependencies
|
|
117
|
+
|
|
118
|
+
This gem includes a vendored copy of
|
|
119
|
+
{word_wrap}[https://rubygems.org/gems/word_wrap] by Radek Pazdera. The vendored
|
|
120
|
+
copy has been lightly updated to remove warnings in use. The original license
|
|
121
|
+
is preserved in lib/chess_data/vendor/word_wrap/LICENSE.txt
|
data/lib/chess_data/database.rb
CHANGED
|
@@ -4,9 +4,9 @@ module ChessData
|
|
|
4
4
|
# Class to store a set of chess games
|
|
5
5
|
#
|
|
6
6
|
# The usual way to create a database is directly from a filename.
|
|
7
|
-
# If your pgn file is called
|
|
7
|
+
# If your pgn file is called "my_games.pgn", create a database using
|
|
8
8
|
#
|
|
9
|
-
# Database.from_file
|
|
9
|
+
# Database.from_file "my_games.pgn"
|
|
10
10
|
#
|
|
11
11
|
class Database
|
|
12
12
|
include Enumerable
|
data/lib/chess_data/game.rb
CHANGED
|
@@ -13,7 +13,7 @@ module ChessData
|
|
|
13
13
|
# puts game.white
|
|
14
14
|
# puts game.black
|
|
15
15
|
#
|
|
16
|
-
# Each of the
|
|
16
|
+
# Each of the "event", "white", "black" values are retrieved from the
|
|
17
17
|
# PGN header.
|
|
18
18
|
#
|
|
19
19
|
# New key values can be created and assigned to, to construct a header for
|
|
@@ -49,7 +49,7 @@ module ChessData
|
|
|
49
49
|
# method_missing is used for accessing key-value terms in the header.
|
|
50
50
|
# * Any unknown method call is checked if it is the key of a header
|
|
51
51
|
# item and, if so, the value for that key is returned.
|
|
52
|
-
# * If the unknown method has an
|
|
52
|
+
# * If the unknown method has an "=" sign in it, a new key is
|
|
53
53
|
# created and assigned a value, which must be an argument to method.
|
|
54
54
|
def method_missing iname, *args
|
|
55
55
|
name = iname.to_s
|
|
@@ -59,7 +59,7 @@ module ChessData
|
|
|
59
59
|
key = name.delete "="
|
|
60
60
|
@header[key] = args[0]
|
|
61
61
|
else
|
|
62
|
-
puts "Unknown key
|
|
62
|
+
puts "Unknown key "#{name}" for header #{@header}"
|
|
63
63
|
super
|
|
64
64
|
end
|
|
65
65
|
end
|
|
@@ -172,7 +172,7 @@ module ChessData
|
|
|
172
172
|
# parse the moves and add to game
|
|
173
173
|
move_str = moves.join(" ")
|
|
174
174
|
if /{.*}/.match(move_str) # remove { } comments
|
|
175
|
-
move_str = $` + " " + $
|
|
175
|
+
move_str = $` + " " + $"
|
|
176
176
|
end
|
|
177
177
|
move_str.split(" ").each do |token|
|
|
178
178
|
case token
|
data/lib/chess_data/moves.rb
CHANGED
|
@@ -60,7 +60,7 @@ module ChessData
|
|
|
60
60
|
private
|
|
61
61
|
|
|
62
62
|
# Return true if moving the giving piece from start to finish
|
|
63
|
-
# will leave the moving side
|
|
63
|
+
# will leave the moving side"s king in check.
|
|
64
64
|
def Moves.king_left_in_check board, piece, start, finish
|
|
65
65
|
test_board = board.clone
|
|
66
66
|
test_board[start] = nil
|
|
@@ -14,8 +14,8 @@ module ChessData
|
|
|
14
14
|
#
|
|
15
15
|
class PositionDefinition
|
|
16
16
|
|
|
17
|
-
# The constructor evaluates the provided _block_, to set up the user
|
|
18
|
-
# board criteria. It then sets up some default criteria for the king
|
|
17
|
+
# The constructor evaluates the provided _block_, to set up the user"s
|
|
18
|
+
# board criteria. It then sets up some default criteria for the king"s and
|
|
19
19
|
# pieces not covered by the block.
|
|
20
20
|
def initialize(&block)
|
|
21
21
|
@matchers = []
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#
|
|
2
|
+
# core_ext.rb
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2015 Radek Pazdera
|
|
5
|
+
# Distributed under the MIT License
|
|
6
|
+
#
|
|
7
|
+
# Optional core exensions, adding the fit and wrap methods to the String class
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
class String
|
|
11
|
+
def wrap(width=WordWrap::DEFAULT_WIDTH)
|
|
12
|
+
WordWrap.ww(self, width, false)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def wrap!(width=WordWrap::DEFAULT_WIDTH)
|
|
16
|
+
replace wrap(width)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def fit(width=WordWrap::DEFAULT_WIDTH)
|
|
20
|
+
WordWrap.ww(self, width, true)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def fit!(width=WordWrap::DEFAULT_WIDTH)
|
|
24
|
+
replace fit(width)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#
|
|
2
|
+
# wrapper.rb
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2014, 2015 Radek Pazdera
|
|
5
|
+
# Distributed under the MIT License
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
module WordWrap
|
|
9
|
+
# TODO: Refactor similar passages out of the two functions into a common one
|
|
10
|
+
class Wrapper
|
|
11
|
+
def initialize(text, width)
|
|
12
|
+
@text = text
|
|
13
|
+
@width = width
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def fit
|
|
17
|
+
lines = []
|
|
18
|
+
next_line = ""
|
|
19
|
+
@text.lines do |line|
|
|
20
|
+
line.chomp! "\n"
|
|
21
|
+
if line.length == 0
|
|
22
|
+
if next_line.length > 0
|
|
23
|
+
lines.push next_line
|
|
24
|
+
next_line = ""
|
|
25
|
+
end
|
|
26
|
+
lines.push ""
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
words = line.split " "
|
|
30
|
+
|
|
31
|
+
words.each do |word|
|
|
32
|
+
word.chomp! "\n"
|
|
33
|
+
|
|
34
|
+
if next_line.length + word.length < @width
|
|
35
|
+
if next_line.length > 0
|
|
36
|
+
next_line << " " << word
|
|
37
|
+
else
|
|
38
|
+
next_line = word
|
|
39
|
+
end
|
|
40
|
+
else
|
|
41
|
+
if word.length >= @width
|
|
42
|
+
lines.push next_line unless next_line == ""
|
|
43
|
+
lines.push word
|
|
44
|
+
next_line = ""
|
|
45
|
+
else
|
|
46
|
+
lines.push next_line
|
|
47
|
+
next_line = word
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
lines.push next_line
|
|
54
|
+
if next_line.length <= 0
|
|
55
|
+
lines.join("\n")
|
|
56
|
+
else
|
|
57
|
+
lines.join("\n") + "\n"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def wrap
|
|
62
|
+
output = []
|
|
63
|
+
|
|
64
|
+
@text.lines do |line|
|
|
65
|
+
line.chomp! "\n"
|
|
66
|
+
if line.length > @width
|
|
67
|
+
new_lines = split_line(line, @width)
|
|
68
|
+
while new_lines.length > 1 && new_lines[1].length > @width
|
|
69
|
+
output.push new_lines[0]
|
|
70
|
+
new_lines = split_line new_lines[1], @width
|
|
71
|
+
end
|
|
72
|
+
output += new_lines
|
|
73
|
+
else
|
|
74
|
+
output.push line
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
output.map { |s| s.rstrip! }
|
|
78
|
+
output.join("\n") + "\n"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def split_line(line, width)
|
|
82
|
+
at = line.index(/\s/)
|
|
83
|
+
last_at = at
|
|
84
|
+
|
|
85
|
+
while at != nil && at < width
|
|
86
|
+
last_at = at
|
|
87
|
+
at = line.index(/\s/, last_at + 1)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
if last_at == nil
|
|
91
|
+
[line]
|
|
92
|
+
else
|
|
93
|
+
[line[0,last_at], line[last_at+1, line.length]]
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright (c) 2014 Radek Pazdera
|
|
2
|
+
# Distributed under the MIT License
|
|
3
|
+
|
|
4
|
+
require_relative "word_wrap/version"
|
|
5
|
+
require_relative "word_wrap/wrapper"
|
|
6
|
+
|
|
7
|
+
module WordWrap
|
|
8
|
+
DEFAULT_WIDTH=80
|
|
9
|
+
|
|
10
|
+
def self.ww(text, width=DEFAULT_WIDTH, fit=false)
|
|
11
|
+
w = Wrapper.new(text, width)
|
|
12
|
+
fit ? w.fit : w.wrap
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/chess_data.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
# Note, the vendored word_wrap fixes a syntactic warning present
|
|
2
|
+
# in the original code.
|
|
3
|
+
require_relative "chess_data/vendor/word_wrap/lib/word_wrap"
|
|
2
4
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
5
|
+
require "chess_data/board.rb"
|
|
6
|
+
require "chess_data/moves.rb"
|
|
7
|
+
require "chess_data/game.rb"
|
|
8
|
+
require "chess_data/database.rb"
|
|
9
|
+
require "chess_data/position-definition.rb"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chess_data
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter Lane
|
|
@@ -10,25 +10,33 @@ cert_chain: []
|
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name:
|
|
13
|
+
name: minitest
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
19
|
-
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
21
|
-
version: 1.0.0
|
|
22
|
-
type: :runtime
|
|
18
|
+
version: '6.0'
|
|
19
|
+
type: :development
|
|
23
20
|
prerelease: false
|
|
24
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
22
|
requirements:
|
|
26
23
|
- - "~>"
|
|
27
24
|
- !ruby/object:Gem::Version
|
|
28
|
-
version: '
|
|
29
|
-
|
|
25
|
+
version: '6.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rake
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '13.0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
30
38
|
- !ruby/object:Gem::Version
|
|
31
|
-
version:
|
|
39
|
+
version: '13.0'
|
|
32
40
|
description: "For searching/filtering datasets of chess games. This gem allows you
|
|
33
41
|
to read \ncollections of games from PGN files, select games which reach positions\nmatching
|
|
34
42
|
specific combinations of pieces, and save these games back in PGN\nformat.\n"
|
|
@@ -47,10 +55,15 @@ files:
|
|
|
47
55
|
- lib/chess_data/game.rb
|
|
48
56
|
- lib/chess_data/moves.rb
|
|
49
57
|
- lib/chess_data/position-definition.rb
|
|
58
|
+
- lib/chess_data/vendor/word_wrap/lib/word_wrap.rb
|
|
59
|
+
- lib/chess_data/vendor/word_wrap/lib/word_wrap/core_ext.rb
|
|
60
|
+
- lib/chess_data/vendor/word_wrap/lib/word_wrap/version.rb
|
|
61
|
+
- lib/chess_data/vendor/word_wrap/lib/word_wrap/wrapper.rb
|
|
50
62
|
homepage: https://rubygems.org/gems/chess_data
|
|
51
63
|
licenses:
|
|
52
64
|
- MIT
|
|
53
65
|
metadata:
|
|
66
|
+
documentation_uri: https://rubydoc.info/gems/chess_data
|
|
54
67
|
source_code_uri: https://codeberg.org/peterlane/chess_data
|
|
55
68
|
rdoc_options:
|
|
56
69
|
- "-m"
|
|
@@ -61,14 +74,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
61
74
|
requirements:
|
|
62
75
|
- - ">="
|
|
63
76
|
- !ruby/object:Gem::Version
|
|
64
|
-
version: '
|
|
77
|
+
version: '3.1'
|
|
65
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
79
|
requirements:
|
|
67
80
|
- - ">="
|
|
68
81
|
- !ruby/object:Gem::Version
|
|
69
82
|
version: '0'
|
|
70
83
|
requirements: []
|
|
71
|
-
rubygems_version:
|
|
84
|
+
rubygems_version: 3.6.9
|
|
72
85
|
specification_version: 4
|
|
73
86
|
summary: For searching/filtering datasets of chess games based on combinations of
|
|
74
87
|
pieces.
|