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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ec0d0d4bf728c0021f9db679a2c0b3208b7a5971888ef4de9490e8dc07037b1
4
- data.tar.gz: eb305d1960b5876c0d31d562a0734cd61f9c7683f0bed5cf5af2c3fb2f8b2f99
3
+ metadata.gz: 0ac52eb2d66dc1963f47ec468aae99c00fde378e31b72721d30250fb8ea8bd38
4
+ data.tar.gz: 6ec6d5b96446757c1f09752641f90a6d38133ca7fda271d71aa9ebc898150aa3
5
5
  SHA512:
6
- metadata.gz: 2a8cc63d397ce5047e9e85b0665f7436af2aff9f59a8dec8d8b9f6ed9abb83b333d0f8f348fc3d460c908dcb6bc6b11338cba2ed7ad8d7af8bb29680dc0ad901
7
- data.tar.gz: d9b5dec6380b0bcd6429e7a61f085330c329f70e75518a7c4471e4c5abab2c7d570c3696ef4034028627b8bb329d3b0aa4a861257d11adeedcaa8d3594a76b0c
6
+ metadata.gz: 0cd3c645277275fca375d33a510a0c26e7b871aada429e8127761be4105d4c2dd8a75911c9e1d447a55bac6f71b462cff0fe4c3f87cf98eefed73ea2dd15cec9
7
+ data.tar.gz: 8e6a99a7a24894a0b9814c703014d5e1eb1e4097dfa430f53bf6b42a6a32bd836fd7069a5df891916b2fe0f70056727b39976c8f128beb8cec8e2647299a9d49
@@ -95,7 +95,7 @@ module ExolveReader
95
95
  end
96
96
 
97
97
  def parse_grid(lines)
98
- grid = lines.map(&:strip).map {|x| x.split(//)}
98
+ grid = lines.map {|x| x.gsub(/\s/, '').split(//)}
99
99
  grid.map do |col|
100
100
  col.map do |c|
101
101
  Cell.new(:solution => parse_grid_char(c))
@@ -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
- scale = 4
13
- png = ChunkyPNG::Image.new(64, 64, ChunkyPNG::Color::TRANSPARENT)
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
- png.rect(0, 0, xw.width * scale, xw.height * scale, stroke_color = red)
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
@@ -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.1'
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.1
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-05 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