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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca64b939037c4c658be062373bc66156605c3833
4
- data.tar.gz: 8792223200b3f4a5bfdcd212127c6724b4a087ae
3
+ metadata.gz: a5a1bfbede1e22eda584f80088055a2da23e973a
4
+ data.tar.gz: 287b4baf8fe41be20437f6c16ad9fd4eca3dbf64
5
5
  SHA512:
6
- metadata.gz: a3361137ff447f19ae7f2db13ca66c259b10a1f13387382881c25d5f63e5b84a7516999bf19c27a4b984ee08553f8461e7db66389e8391fe2f867b8523bd3aa5
7
- data.tar.gz: becb38b39f34b7e25876e5d1a7d148bb92a205fd59230fbb11ea465680099bf65bc46952391df8dafb8a6cf8f9aba7d073388d20504a92c2224058e0ccc689e7
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
@@ -27,7 +27,7 @@ class Text < Plugin
27
27
  end
28
28
 
29
29
  def format_clues(numbers, clues, indent)
30
- numbers.zip(clues).map {|n, c| " "*indent + "#{n}. #{c}"}.join("\n")
30
+ numbers.zip(clues).map {|n, c| " "*indent + "#{n.to_s.rjust(2)}. #{c}"}.join("\n")
31
31
  end
32
32
  end
33
33
 
@@ -1,3 +1,3 @@
1
1
  module Pangrid
2
- VERSION='0.3.0'
2
+ VERSION='0.3.1'
3
3
  end
@@ -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
- def number
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
- across << n if across? x, y
94
- down << n if down? x, y
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, char = self.rebus[s]
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.0
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 00:00:00.000000000 Z
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