pangrid 0.5.2 → 0.5.3
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/pangrid/plugins/qxw.rb +36 -14
- data/lib/pangrid/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ac52eb2d66dc1963f47ec468aae99c00fde378e31b72721d30250fb8ea8bd38
|
4
|
+
data.tar.gz: 6ec6d5b96446757c1f09752641f90a6d38133ca7fda271d71aa9ebc898150aa3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cd3c645277275fca375d33a510a0c26e7b871aada429e8127761be4105d4c2dd8a75911c9e1d447a55bac6f71b462cff0fe4c3f87cf98eefed73ea2dd15cec9
|
7
|
+
data.tar.gz: 8e6a99a7a24894a0b9814c703014d5e1eb1e4097dfa430f53bf6b42a6a32bd836fd7069a5df891916b2fe0f70056727b39976c8f128beb8cec8e2647299a9d49
|
data/lib/pangrid/plugins/qxw.rb
CHANGED
@@ -8,25 +8,33 @@ class Qxw < Plugin
|
|
8
8
|
|
9
9
|
DESCRIPTION = "QXW grid reader (rectangular grids only)"
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
lines = data.lines.map(&:chomp)
|
14
|
-
gp = lines.find {|x| x =~ /^GP( \d+){6}$/}
|
15
|
-
check("Could not read grid size from .qxw file") { gp }
|
16
|
-
type, w, h, _ = gp.scan(/\d+/).map(&:to_i)
|
17
|
-
check("Only rectangular grids are supported") { type == 0 }
|
18
|
-
xw.width = w
|
19
|
-
xw.height = h
|
20
|
-
xw.solution = []
|
11
|
+
def read_black(xw, lines)
|
12
|
+
# Read black cells
|
21
13
|
grid = lines.select {|x| x =~ /^SQ /}
|
22
14
|
grid.each do |line|
|
23
15
|
parts = line.scan(/\w+/)
|
24
16
|
check(QXW_GRID_ERROR) { parts.length == 6 || parts.length == 7 }
|
25
|
-
col, row,
|
17
|
+
_, col, row, _, _, b, _ = parts
|
18
|
+
col, row, b = col.to_i, row.to_i, b.to_i
|
19
|
+
next if b != 1
|
20
|
+
cell = Cell.new
|
21
|
+
cell.solution = :black
|
22
|
+
xw.solution[row] ||= []
|
23
|
+
xw.solution[row][col] = cell
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def read_filled(xw, lines)
|
28
|
+
# Read filled cells
|
29
|
+
grid = lines.select {|x| x =~ /^SQCT /}
|
30
|
+
grid.each do |line|
|
31
|
+
parts = line.scan(/\w+/)
|
32
|
+
check(QXW_GRID_ERROR) { parts.length == 4 || parts.length == 5 }
|
33
|
+
_, col, row, d, c = parts
|
34
|
+
col, row, d = col.to_i, row.to_i, d.to_i
|
35
|
+
next if d != 0 # different char per direction, not supported for now
|
26
36
|
cell = Cell.new
|
27
|
-
if
|
28
|
-
cell.solution = :black
|
29
|
-
elsif c == nil
|
37
|
+
if c == nil
|
30
38
|
cell.solution = :null
|
31
39
|
else
|
32
40
|
cell.solution = c
|
@@ -34,6 +42,20 @@ class Qxw < Plugin
|
|
34
42
|
xw.solution[row] ||= []
|
35
43
|
xw.solution[row][col] = cell
|
36
44
|
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def read(data)
|
48
|
+
xw = XWord.new
|
49
|
+
lines = data.lines.map(&:chomp)
|
50
|
+
gp = lines.find {|x| x =~ /^GP( \d+){6}$/}
|
51
|
+
check("Could not read grid size from .qxw file") { gp }
|
52
|
+
type, w, h, _ = gp.scan(/\d+/).map(&:to_i)
|
53
|
+
check("Only rectangular grids are supported") { type == 0 }
|
54
|
+
xw.width = w
|
55
|
+
xw.height = h
|
56
|
+
xw.solution = []
|
57
|
+
read_filled(xw, lines)
|
58
|
+
read_black(xw, lines)
|
37
59
|
check(QXW_GRID_ERROR) { xw.solution.length == xw.height }
|
38
60
|
check(QXW_GRID_ERROR) { xw.solution.all? {|i| i.compact.length == xw.width} }
|
39
61
|
|
data/lib/pangrid/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pangrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin DeMello
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webrick
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
|
-
rubygems_version: 3.
|
76
|
+
rubygems_version: 3.3.7
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: A crossword file format converter
|