pangrid 0.5.1 → 0.5.3
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/exolve.rb +1 -1
- data/lib/pangrid/plugins/png.rb +13 -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/png.rb
CHANGED
@@ -3,21 +3,30 @@ require 'chunky_png'
|
|
3
3
|
module Pangrid
|
4
4
|
|
5
5
|
class PNGThumbnail < Plugin
|
6
|
+
attr_reader :scale, :border
|
7
|
+
|
8
|
+
def initialize(scale = 4, border = [128, 0, 0])
|
9
|
+
@scale = scale
|
10
|
+
@border = border
|
11
|
+
end
|
6
12
|
|
7
13
|
def write(xw)
|
8
14
|
black = ChunkyPNG::Color::BLACK
|
9
15
|
white = ChunkyPNG::Color::WHITE
|
10
|
-
red = ChunkyPNG::Color::rgb(255, 0, 0)
|
11
16
|
grey = ChunkyPNG::Color::rgb(128, 128, 128)
|
12
|
-
|
13
|
-
|
17
|
+
xdim = xw.width * scale + 2
|
18
|
+
ydim = xw.height * scale + 2
|
19
|
+
png = ChunkyPNG::Image.new(xdim, ydim, ChunkyPNG::Color::TRANSPARENT)
|
14
20
|
xw.each_cell_with_coords do |x, y, cell|
|
15
21
|
c = cell.black? ? black : white
|
16
22
|
png.rect(
|
17
23
|
x * scale, y * scale, (x + 1) * scale, (y + 1) * scale,
|
18
24
|
stroke_color = grey, fill_color = c)
|
19
25
|
end
|
20
|
-
|
26
|
+
if border
|
27
|
+
stroke = ChunkyPNG::Color::rgb(*border)
|
28
|
+
png.rect(0, 0, xw.width * scale, xw.height * scale, stroke_color = stroke)
|
29
|
+
end
|
21
30
|
png.to_blob
|
22
31
|
end
|
23
32
|
end
|
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
|