pangrid 0.4.0 → 0.5.2
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/csv.rb +1 -1
- data/lib/pangrid/plugins/exolve.rb +65 -1
- data/lib/pangrid/plugins/png.rb +34 -0
- data/lib/pangrid/plugins/reddit.rb +1 -0
- data/lib/pangrid/version.rb +1 -1
- data/lib/pangrid/xw.rb +8 -0
- metadata +23 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e04bea2f4ebdb7947ec122f28a4a8feaa9cb4e7c4a27206abb6ef0fe7e6f254c
|
4
|
+
data.tar.gz: d5f32ec895146fe2141c5f68dcf775477b7a381577239e8225d8d8a155fe0c10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8057bad79f07c4d761f136a8258171b5b7a3711d5d72d589282d7219153fbf6bbb28c29315ab0ee99eba74ef465d334dbef71fd7657e8881dfe42ad944076ac
|
7
|
+
data.tar.gz: e8bf9a1582e69ab4279505d19f957dbe3668cb471cd2644660fbaff073a08f3b608de57db830f637c6a97ada3f255e79bcbc59bab45f0e8d9e9ff345cc0636f8
|
data/lib/pangrid/plugins/csv.rb
CHANGED
@@ -33,7 +33,7 @@ module ExolveWriter
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def format_clues(numbers, clues)
|
36
|
-
numbers.zip(clues).map {|n, c| "#{n.to_s.rjust(2)}
|
36
|
+
numbers.zip(clues).map {|n, c| "#{n.to_s.rjust(2)} #{c}"}
|
37
37
|
end
|
38
38
|
|
39
39
|
def indent(lines)
|
@@ -41,7 +41,71 @@ module ExolveWriter
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
module ExolveReader
|
45
|
+
def read(data)
|
46
|
+
s = data.each_line.map(&:rstrip)
|
47
|
+
first = s.index('exolve-begin')
|
48
|
+
check("exolve-begin missing") { first }
|
49
|
+
last = s.index('exolve-end')
|
50
|
+
check("exolve-end missing") { last }
|
51
|
+
lines = s[(first + 1)...last]
|
52
|
+
xw = XWord.new
|
53
|
+
s = sections(lines)
|
54
|
+
s.each do |_, field, data|
|
55
|
+
if %w(title setter copyright prelude).include? field
|
56
|
+
xw[field] = data
|
57
|
+
elsif %w(height width).include? field
|
58
|
+
xw[field] = data.to_i
|
59
|
+
elsif %(across down).include? field
|
60
|
+
xw["#{field}_clues"] = data
|
61
|
+
elsif field == "grid"
|
62
|
+
xw.solution = parse_grid(data)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
xw
|
66
|
+
end
|
67
|
+
|
68
|
+
def sections(lines)
|
69
|
+
headers = lines.each.with_index.map do |l, i|
|
70
|
+
m = l.match(/^(\s+)exolve-(\w+):(.*)$/)
|
71
|
+
if m
|
72
|
+
_, indent, field, data = m.to_a
|
73
|
+
[i, field, data.strip]
|
74
|
+
else
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
headers.compact!
|
79
|
+
headers.push([lines.length, "", ""])
|
80
|
+
headers.each_cons(2) do |i, j|
|
81
|
+
if i[2].empty?
|
82
|
+
i[2] = lines[(i[0] + 1)...j[0]].map(&:strip)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
headers.pop
|
86
|
+
headers
|
87
|
+
end
|
88
|
+
|
89
|
+
def parse_grid_char(char)
|
90
|
+
case char
|
91
|
+
when '0'; :null
|
92
|
+
when '.'; :black
|
93
|
+
else; char
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def parse_grid(lines)
|
98
|
+
grid = lines.map {|x| x.gsub(/\s/, '').split(//)}
|
99
|
+
grid.map do |col|
|
100
|
+
col.map do |c|
|
101
|
+
Cell.new(:solution => parse_grid_char(c))
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
44
107
|
class ExolveFilled < Plugin
|
108
|
+
include ExolveReader
|
45
109
|
include ExolveWriter
|
46
110
|
|
47
111
|
DESCRIPTION = "Exolve writer with solutions"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'chunky_png'
|
2
|
+
|
3
|
+
module Pangrid
|
4
|
+
|
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
|
12
|
+
|
13
|
+
def write(xw)
|
14
|
+
black = ChunkyPNG::Color::BLACK
|
15
|
+
white = ChunkyPNG::Color::WHITE
|
16
|
+
grey = ChunkyPNG::Color::rgb(128, 128, 128)
|
17
|
+
xdim = xw.width * scale + 2
|
18
|
+
ydim = xw.height * scale + 2
|
19
|
+
png = ChunkyPNG::Image.new(xdim, ydim, ChunkyPNG::Color::TRANSPARENT)
|
20
|
+
xw.each_cell_with_coords do |x, y, cell|
|
21
|
+
c = cell.black? ? black : white
|
22
|
+
png.rect(
|
23
|
+
x * scale, y * scale, (x + 1) * scale, (y + 1) * scale,
|
24
|
+
stroke_color = grey, fill_color = c)
|
25
|
+
end
|
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
|
30
|
+
png.to_blob
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end # module Pangrid
|
@@ -92,6 +92,7 @@ class RedditBlank < Plugin
|
|
92
92
|
#
|
93
93
|
# we have to be careful about leading/trailing |s
|
94
94
|
ix = lines.find_index {|row| row =~ /^[|\s-]+$/}
|
95
|
+
check("Could not find grid") { not ix.nil? }
|
95
96
|
width = lines[ix].gsub(/\s/, '').split('|').reject(&:empty?).length
|
96
97
|
lines = [lines[(ix - 1)]] + lines[(ix + 1) .. -1]
|
97
98
|
grid = lines.take_while {|i| is_grid_row(i)}
|
data/lib/pangrid/version.rb
CHANGED
data/lib/pangrid/xw.rb
CHANGED
@@ -139,6 +139,14 @@ class XWord < OpenStruct
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
+
def each_cell_with_coords
|
143
|
+
(0 ... height).each do |y|
|
144
|
+
(0 ... width).each do |x|
|
145
|
+
yield [x, y, solution[y][x]]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
142
150
|
# {:black => char, :null => char} -> Any[][]
|
143
151
|
def to_array(opts = {})
|
144
152
|
opts = {:black => '#', :null => ' '}.merge(opts)
|
metadata
CHANGED
@@ -1,16 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pangrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin DeMello
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2022-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webrick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.7.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.7.0
|
27
|
+
description:
|
14
28
|
email: martindemello@gmail.com
|
15
29
|
executables:
|
16
30
|
- pangrid
|
@@ -31,6 +45,7 @@ files:
|
|
31
45
|
- lib/pangrid/plugins/excel.rb
|
32
46
|
- lib/pangrid/plugins/exolve.rb
|
33
47
|
- lib/pangrid/plugins/json.rb
|
48
|
+
- lib/pangrid/plugins/png.rb
|
34
49
|
- lib/pangrid/plugins/qxw.rb
|
35
50
|
- lib/pangrid/plugins/reddit.rb
|
36
51
|
- lib/pangrid/plugins/text.rb
|
@@ -41,7 +56,7 @@ homepage: https://github.com/martindemello/pangrid
|
|
41
56
|
licenses:
|
42
57
|
- MIT
|
43
58
|
metadata: {}
|
44
|
-
post_install_message:
|
59
|
+
post_install_message:
|
45
60
|
rdoc_options:
|
46
61
|
- "--main"
|
47
62
|
- README
|
@@ -58,8 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
73
|
- !ruby/object:Gem::Version
|
59
74
|
version: '0'
|
60
75
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
62
|
-
signing_key:
|
76
|
+
rubygems_version: 3.2.22
|
77
|
+
signing_key:
|
63
78
|
specification_version: 4
|
64
79
|
summary: A crossword file format converter
|
65
80
|
test_files: []
|