pangrid 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e04bea2f4ebdb7947ec122f28a4a8feaa9cb4e7c4a27206abb6ef0fe7e6f254c
4
- data.tar.gz: d5f32ec895146fe2141c5f68dcf775477b7a381577239e8225d8d8a155fe0c10
3
+ metadata.gz: 0ac52eb2d66dc1963f47ec468aae99c00fde378e31b72721d30250fb8ea8bd38
4
+ data.tar.gz: 6ec6d5b96446757c1f09752641f90a6d38133ca7fda271d71aa9ebc898150aa3
5
5
  SHA512:
6
- metadata.gz: d8057bad79f07c4d761f136a8258171b5b7a3711d5d72d589282d7219153fbf6bbb28c29315ab0ee99eba74ef465d334dbef71fd7657e8881dfe42ad944076ac
7
- data.tar.gz: e8bf9a1582e69ab4279505d19f957dbe3668cb471cd2644660fbaff073a08f3b608de57db830f637c6a97ada3f255e79bcbc59bab45f0e8d9e9ff345cc0636f8
6
+ metadata.gz: 0cd3c645277275fca375d33a510a0c26e7b871aada429e8127761be4105d4c2dd8a75911c9e1d447a55bac6f71b462cff0fe4c3f87cf98eefed73ea2dd15cec9
7
+ data.tar.gz: 8e6a99a7a24894a0b9814c703014d5e1eb1e4097dfa430f53bf6b42a6a32bd836fd7069a5df891916b2fe0f70056727b39976c8f128beb8cec8e2647299a9d49
@@ -8,25 +8,33 @@ class Qxw < Plugin
8
8
 
9
9
  DESCRIPTION = "QXW grid reader (rectangular grids only)"
10
10
 
11
- def read(data)
12
- xw = XWord.new
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, b, c = parts[1].to_i, parts[2].to_i, parts[5].to_i, parts[6]
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 b == 1
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
 
@@ -1,3 +1,3 @@
1
1
  module Pangrid
2
- VERSION='0.5.2'
2
+ VERSION='0.5.3'
3
3
  end
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.2
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: 2022-02-21 00:00:00.000000000 Z
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.2.22
76
+ rubygems_version: 3.3.7
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: A crossword file format converter