pangrid 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pangrid/plugins/qxw.rb +46 -0
- data/lib/pangrid/plugins/text.rb +1 -1
- data/lib/pangrid/version.rb +1 -1
- data/lib/pangrid/xw.rb +35 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5a1bfbede1e22eda584f80088055a2da23e973a
|
4
|
+
data.tar.gz: 287b4baf8fe41be20437f6c16ad9fd4eca3dbf64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 987f63c04f51c1575d2d47a82f9fdcafd2645656e5a6facc5ea77e8e02fff8216ac2d591c52e23909e00a5c149a67bb80937c936b2b7b8d8328a34f3d4751446
|
7
|
+
data.tar.gz: 721b3f3ea706c965ca1a2fbd04d098a55c88aa97478dc2773c7faf03c46bc4461454000577117c7d3d53b8862ebc6ea9f706800be176731e7c33a0c9f4a1402c
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Qxw savefile for rectangular grids [http://www.quinapalus.com/qxw.html]
|
2
|
+
|
3
|
+
module Pangrid
|
4
|
+
|
5
|
+
QXW_GRID_ERROR = "Could not read grid from .qxw file"
|
6
|
+
|
7
|
+
class Qxw < Plugin
|
8
|
+
def read(data)
|
9
|
+
xw = XWord.new
|
10
|
+
lines = data.lines.map(&:chomp)
|
11
|
+
gp = lines.find {|x| x =~ /^GP( \d+){6}$/}
|
12
|
+
check("Could not read grid size from .qxw file") { gp }
|
13
|
+
type, w, h, _ = gp.scan(/\d+/).map(&:to_i)
|
14
|
+
check("Only rectangular grids are supported") { type == 0 }
|
15
|
+
xw.width = w
|
16
|
+
xw.height = h
|
17
|
+
xw.solution = []
|
18
|
+
grid = lines.select {|x| x =~ /^SQ /}
|
19
|
+
grid.each do |line|
|
20
|
+
parts = line.scan(/\w+/)
|
21
|
+
check(QXW_GRID_ERROR) { parts.length == 6 || parts.length == 7 }
|
22
|
+
col, row, b, c = parts[1].to_i, parts[2].to_i, parts[5].to_i, parts[6]
|
23
|
+
cell = Cell.new
|
24
|
+
if b == 1
|
25
|
+
cell.solution = :black
|
26
|
+
elsif c == nil
|
27
|
+
cell.solution = :null
|
28
|
+
else
|
29
|
+
cell.solution = c
|
30
|
+
end
|
31
|
+
xw.solution[row] ||= []
|
32
|
+
xw.solution[row][col] = cell
|
33
|
+
end
|
34
|
+
check(QXW_GRID_ERROR) { xw.solution.length == xw.height }
|
35
|
+
check(QXW_GRID_ERROR) { xw.solution.all? {|i| i.compact.length == xw.width} }
|
36
|
+
|
37
|
+
# Placeholder clues
|
38
|
+
_, _, words_a, words_d = xw.number(true)
|
39
|
+
xw.across_clues = words_a.map {|i| "[#{i}]" }
|
40
|
+
xw.down_clues = words_d.map {|i| "[#{i}]" }
|
41
|
+
|
42
|
+
xw
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end # module Pangrid
|
data/lib/pangrid/plugins/text.rb
CHANGED
data/lib/pangrid/version.rb
CHANGED
data/lib/pangrid/xw.rb
CHANGED
@@ -53,6 +53,15 @@ class Cell
|
|
53
53
|
rebus? ? solution.to_char : solution
|
54
54
|
end
|
55
55
|
|
56
|
+
def to_w
|
57
|
+
case solution
|
58
|
+
when :black; '#'
|
59
|
+
when :null; '.'
|
60
|
+
when Rebus; solution.inspect
|
61
|
+
else; solution
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
56
65
|
def inspect
|
57
66
|
case solution
|
58
67
|
when :black; '#'
|
@@ -86,19 +95,40 @@ class XWord < OpenStruct
|
|
86
95
|
boundary?(x, y - 1) && !boundary?(x, y) && !boundary?(x, y + 1)
|
87
96
|
end
|
88
97
|
|
89
|
-
|
98
|
+
# Word starting from a square
|
99
|
+
def word_from(x, y, dir)
|
100
|
+
s = ""
|
101
|
+
while !boundary?(x, y) do
|
102
|
+
s += solution[y][x].to_w
|
103
|
+
if dir == :across
|
104
|
+
x += 1
|
105
|
+
else
|
106
|
+
y += 1
|
107
|
+
end
|
108
|
+
end
|
109
|
+
s
|
110
|
+
end
|
111
|
+
|
112
|
+
def number(words = false)
|
90
113
|
n, across, down = 1, [], []
|
114
|
+
words_a, words_d = [], []
|
91
115
|
(0 ... height).each do |y|
|
92
116
|
(0 ... width).each do |x|
|
93
|
-
|
94
|
-
|
117
|
+
if across? x, y
|
118
|
+
across << n
|
119
|
+
words_a << word_from(x, y, :across)
|
120
|
+
end
|
121
|
+
if down? x, y
|
122
|
+
down << n
|
123
|
+
words_d << word_from(x, y, :down)
|
124
|
+
end
|
95
125
|
if across.last == n || down.last == n
|
96
126
|
solution[y][x].number = n
|
97
127
|
n += 1
|
98
128
|
end
|
99
129
|
end
|
100
130
|
end
|
101
|
-
[across, down]
|
131
|
+
words ? [across, down, words_a, words_d] : [across, down]
|
102
132
|
end
|
103
133
|
|
104
134
|
def each_cell
|
@@ -137,7 +167,7 @@ class XWord < OpenStruct
|
|
137
167
|
if c.rebus?
|
138
168
|
r = c.solution
|
139
169
|
if self.rebus[s]
|
140
|
-
sym,
|
170
|
+
sym, _ = self.rebus[s]
|
141
171
|
r.symbol = sym.to_s
|
142
172
|
else
|
143
173
|
k += 1
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin DeMello
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: martindemello@gmail.com
|
@@ -29,6 +29,7 @@ files:
|
|
29
29
|
- lib/pangrid/plugins/acrosslite.rb
|
30
30
|
- lib/pangrid/plugins/csv.rb
|
31
31
|
- lib/pangrid/plugins/excel.rb
|
32
|
+
- lib/pangrid/plugins/qxw.rb
|
32
33
|
- lib/pangrid/plugins/reddit.rb
|
33
34
|
- lib/pangrid/plugins/text.rb
|
34
35
|
- lib/pangrid/utils.rb
|