pangrid 0.4.1 → 0.5.0

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: b922856376c54ffb6833389f2ac8d853931bfbd9201426f1349cac4c2c967a89
4
- data.tar.gz: 0a003d8ba96839df14cf901d12f5ccbae16b298534358aafc094b8f9cc4c5271
3
+ metadata.gz: 33b68bb3ffccf5e357c16637245e4488b3541070737f171e2773e035ccdfbcfd
4
+ data.tar.gz: 05b0853605cccef29232acb6f96e1a53e1356e830e85a7c158595c426c179fbf
5
5
  SHA512:
6
- metadata.gz: ad9155c77fe8ef2d3b7cc75873fc606a92af5f4783f3f2a96ce402e5d52a634c6c0b3cf8e2228b2d2f2bacab5ac91948ce1755a3b0eee53b2b8825ecc64778ff
7
- data.tar.gz: 4e09a65ed0ead53dac843bf6fa570bc319369c44cd22280199e2c018f7ca663bb3e386bc40faff0bd8ad77237729b09805d0033da13a7a2306e8454a4aa2449b
6
+ metadata.gz: '00778b056954ae735461bc4782e5c9aae027ac6d0b2928a6253507afa8113abbc26ee908ba4e68b49c42d128a15b38406604eb6303e6214af88969824c2854b9'
7
+ data.tar.gz: de0cd413482c54b815ecf2eb97b41511b1a309858d61a2e3571cfff98fb1d6478fda2d5f4c332142253ae25969fa682dca97ddcb8d68d49f39b162f248614630
@@ -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(&:strip).map {|x| x.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,25 @@
1
+ require 'chunky_png'
2
+
3
+ module Pangrid
4
+
5
+ class PNGThumbnail < Plugin
6
+
7
+ def write(xw)
8
+ black = ChunkyPNG::Color::BLACK
9
+ white = ChunkyPNG::Color::WHITE
10
+ red = ChunkyPNG::Color::rgb(255, 0, 0)
11
+ grey = ChunkyPNG::Color::rgb(128, 128, 128)
12
+ scale = 4
13
+ png = ChunkyPNG::Image.new(64, 64, ChunkyPNG::Color::TRANSPARENT)
14
+ xw.each_cell_with_coords do |x, y, cell|
15
+ c = cell.black? ? black : white
16
+ png.rect(
17
+ x * scale, y * scale, (x + 1) * scale, (y + 1) * scale,
18
+ stroke_color = grey, fill_color = c)
19
+ end
20
+ png.rect(0, 0, xw.width * scale, xw.height * scale, stroke_color = red)
21
+ png.to_blob
22
+ end
23
+ end
24
+
25
+ end # module Pangrid
@@ -1,3 +1,3 @@
1
1
  module Pangrid
2
- VERSION='0.4.1'
2
+ VERSION='0.5.0'
3
3
  end
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.1
4
+ version: 0.5.0
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: 2019-08-25 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
11
+ date: 2021-10-04 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.0.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: []