pangrid 0.3.1 → 0.4.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
- SHA1:
3
- metadata.gz: a5a1bfbede1e22eda584f80088055a2da23e973a
4
- data.tar.gz: 287b4baf8fe41be20437f6c16ad9fd4eca3dbf64
2
+ SHA256:
3
+ metadata.gz: be115d7cba3bf82d65d241afb1fedb1becfa8085d447590960447fc479b57d90
4
+ data.tar.gz: 5520cd33d623bb0f55f11d0eb3fe4c9e2187dc437e3675bd2b97d40bb60cef08
5
5
  SHA512:
6
- metadata.gz: 987f63c04f51c1575d2d47a82f9fdcafd2645656e5a6facc5ea77e8e02fff8216ac2d591c52e23909e00a5c149a67bb80937c936b2b7b8d8328a34f3d4751446
7
- data.tar.gz: 721b3f3ea706c965ca1a2fbd04d098a55c88aa97478dc2773c7faf03c46bc4461454000577117c7d3d53b8862ebc6ea9f706800be176731e7c33a0c9f4a1402c
6
+ metadata.gz: 607c19e615b28a3ad2117765ebba9d5003aaec081e04b0dac4793fdc3a32e88d99b9fbe6c40b3739c116b20a0bcb7e263f00c223dca6898b35f65729c358fed9
7
+ data.tar.gz: 6df6cf0d9a78dbaef9213722a80538e0da262dcdb2026e862da07f0235154d2688f2bfc26397b67bd9a2e8a9975ff2a8a3c453fd6427a098d6dc912c011a1643
@@ -26,11 +26,30 @@ class Servlet < WEBrick::HTTPServlet::AbstractServlet
26
26
  rescue Exception => e
27
27
  out = e.inspect
28
28
  end
29
-
30
- template = IO.read(TEMPLATE)
31
- response.status = 200
32
- response.content_type = "text/html"
33
- response.body = template % out
29
+
30
+ response.header['Access-Control-Allow-Origin'] = '*'
31
+
32
+ case request.path
33
+ when "/"
34
+ template = IO.read(TEMPLATE)
35
+ response.status = 200
36
+ response.content_type = "text/html"
37
+ response.body = template % out
38
+ when "/blob"
39
+ response.status = 200
40
+ response.content_type = "application/octet-stream"
41
+ response.body = out
42
+ when "/json"
43
+ if request.query["to"] == "json"
44
+ response.status = 200
45
+ response.content_type = "text/json"
46
+ response.body = out
47
+ else
48
+ response.status = 200
49
+ response.content_type = "text/json"
50
+ response.body = '{ "error" : "non-json format requested" }'
51
+ end
52
+ end
34
53
  end
35
54
  end
36
55
 
@@ -35,6 +35,8 @@ class Plugin
35
35
  FAILED = []
36
36
  MISSING_DEPS = {}
37
37
 
38
+ DESCRIPTION = ""
39
+
38
40
  def self.inherited(subclass)
39
41
  name = class_to_name(subclass.name)
40
42
  #puts "Registered #{subclass} as #{name}"
@@ -62,13 +64,13 @@ class Plugin
62
64
 
63
65
  def self.list_all
64
66
  puts "-------------------------------------------------------"
65
- puts "Available plugins:"
67
+ puts "Available plugins (F = from, T = to):"
66
68
  puts "-------------------------------------------------------"
67
69
  REGISTRY.keys.sort.each do |name|
68
70
  plugin = REGISTRY[name]
69
71
  provides = [:read, :write].select {|m| plugin.method_defined? m}
70
- provides = provides.map {|m| {read: 'from', write: 'to'}[m]}
71
- puts " " + name + " [" + provides.join(", ") + "]"
72
+ provides = provides.map {|m| {read: 'F', write: 'T'}[m]}.join
73
+ puts " #{name} [#{provides}]".ljust(30) + plugin.const_get(:DESCRIPTION)
72
74
  end
73
75
  if !MISSING_DEPS.empty?
74
76
  puts
@@ -75,6 +75,8 @@ class AcrossLiteBinary < Plugin
75
75
  # crossword, checksums
76
76
  attr_accessor :xw, :cs
77
77
 
78
+ DESCRIPTION = "AcrossLite binary format (.puz)"
79
+
78
80
  HEADER_FORMAT = "v A12 v V2 A4 v2 A12 c2 v3"
79
81
  HEADER_CHECKSUM_FORMAT = "c2 v3"
80
82
  EXT_HEADER_FORMAT = "A4 v2"
@@ -359,6 +361,8 @@ class AcrossLiteText < Plugin
359
361
 
360
362
  attr_accessor :xw, :rebus
361
363
 
364
+ DESCRIPTION = "AcrossLite text format"
365
+
362
366
  def initialize
363
367
  @xw = XWord.new
364
368
  end
@@ -26,6 +26,9 @@ require 'csv'
26
26
  module Pangrid
27
27
 
28
28
  class CSV < Plugin
29
+
30
+ DESCRIPTION = "CSV reader (see source comments for format)"
31
+
29
32
  def read(data)
30
33
  s = ::CSV.parse(data)
31
34
  s.reject! {|row| row.compact.empty?}
@@ -11,6 +11,9 @@ module Pangrid
11
11
  require_for_plugin 'excel', ['axlsx']
12
12
 
13
13
  class ExcelXSLX < Plugin
14
+
15
+ DESCRIPTION = "Excel writer. Useful to upload to google sheets."
16
+
14
17
  # styles
15
18
  STYLES = {
16
19
  :black => {:bg_color => "00"},
@@ -0,0 +1,64 @@
1
+ # Exolve (https://github.com/viresh-ratnakar/exolve) is a browser-based
2
+ # crossword solver that allows you to embed the crossword and solving software
3
+ # in a single HTML file.
4
+
5
+ module Pangrid
6
+
7
+ module ExolveWriter
8
+ def write(xw)
9
+ headers = format_headers(xw)
10
+ across, down = xw.number
11
+ grid = format_grid(xw)
12
+ ac = format_clues(across, xw.across_clues)
13
+ dn = format_clues(down, xw.down_clues)
14
+ across = ["exolve-across:"] + indent(ac)
15
+ down = ["exolve-down:"] + indent(dn)
16
+ grid = ["exolve-grid:"] + indent(grid)
17
+ body = headers + grid + across + down
18
+ out = ["exolve-begin"] + indent(body) + ["exolve-end"]
19
+ out.join("\n")
20
+ end
21
+
22
+ def format_headers(xw)
23
+ headers = [
24
+ 'id', 'replace-with-unique-id',
25
+ 'title', xw.title,
26
+ 'setter', xw.author,
27
+ 'width', xw.width,
28
+ 'height', xw.height,
29
+ 'copyright', xw.copyright,
30
+ 'prelude', xw.preamble
31
+ ]
32
+ headers.each_slice(2).select {|k, v| v}.map {|k, v| "exolve-#{k}: #{v}"}
33
+ end
34
+
35
+ def format_clues(numbers, clues)
36
+ numbers.zip(clues).map {|n, c| "#{n.to_s.rjust(2)}. #{c}"}
37
+ end
38
+
39
+ def indent(lines)
40
+ lines.map {|x| " " + x}
41
+ end
42
+ end
43
+
44
+ class ExolveFilled < Plugin
45
+ include ExolveWriter
46
+
47
+ DESCRIPTION = "Exolve writer with solutions"
48
+
49
+ def format_grid(xw)
50
+ xw.to_array(:black => '.', :null => '0').map(&:join)
51
+ end
52
+ end
53
+
54
+ class ExolveBlank < Plugin
55
+ include ExolveWriter
56
+
57
+ DESCRIPTION = "Exolve writer without solutions"
58
+
59
+ def format_grid(xw)
60
+ xw.to_array(:black => '.', :null => '0') {|c| 0}.map(&:join)
61
+ end
62
+ end
63
+
64
+ end # module Pangrid
@@ -0,0 +1,78 @@
1
+ # Json
2
+ #
3
+ # cell = { x : int, y : int, contents : string }
4
+ #
5
+ # xword = { rows : int,
6
+ # cols : int,
7
+ # cells : [cell],
8
+ # across : [string]
9
+ # down : [string]
10
+ # }
11
+
12
+ require 'json'
13
+
14
+ module Pangrid
15
+
16
+ class Json < Plugin
17
+
18
+ DESCRIPTION = "Simple JSON format"
19
+
20
+ def write(xw)
21
+ cells = []
22
+ (0 ... xw.height).each do |y|
23
+ (0 ... xw.width).each do |x|
24
+ cell = xw.solution[y][x]
25
+ s = case cell.solution
26
+ when :black; '#'
27
+ when :null; ''
28
+ when Rebus; cell.solution.inspect
29
+ else; cell.solution
30
+ end
31
+
32
+ cells.push({ x: x, y: y, contents: s })
33
+ end
34
+ end
35
+
36
+ h = {
37
+ rows: xw.height,
38
+ cols: xw.width,
39
+ cells: cells,
40
+ across: xw.across_clues,
41
+ down: xw.down_clues
42
+ }
43
+
44
+ ::JSON.generate(h)
45
+ end
46
+
47
+ def read(data)
48
+ json = ::JSON.parse(data)
49
+ xw = XWord.new
50
+
51
+ xw.height = json['rows']
52
+ xw.width = json['cols']
53
+ xw.solution = Array.new(xw.height) { Array.new(xw.width) }
54
+ json['cells'].each do |c|
55
+ cell = Cell.new
56
+ s = c['contents']
57
+ cell.solution =
58
+ case s
59
+ when ""; :null
60
+ when "#"; :black
61
+ else
62
+ if s.length == 1
63
+ s
64
+ else
65
+ Rebus.new s
66
+ end
67
+ end
68
+ x, y = c['x'], c['y']
69
+ xw.solution[y][x] = cell
70
+ end
71
+ xw.across_clues = json['across']
72
+ xw.down_clues = json['down']
73
+ xw
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -5,6 +5,9 @@ module Pangrid
5
5
  QXW_GRID_ERROR = "Could not read grid from .qxw file"
6
6
 
7
7
  class Qxw < Plugin
8
+
9
+ DESCRIPTION = "QXW grid reader (rectangular grids only)"
10
+
8
11
  def read(data)
9
12
  xw = XWord.new
10
13
  lines = data.lines.map(&:chomp)
@@ -34,6 +34,8 @@ end
34
34
  class RedditFilled < Plugin
35
35
  include RedditWriter
36
36
 
37
+ DESCRIPTION = "Reddit format (with filled squares)"
38
+
37
39
  def write(xw)
38
40
  write_xw(xw)
39
41
  end
@@ -48,6 +50,8 @@ end
48
50
  class RedditBlank < Plugin
49
51
  include RedditWriter
50
52
 
53
+ DESCRIPTION = "Reddit format (with blank squares)"
54
+
51
55
  def write(xw)
52
56
  write_xw(xw)
53
57
  end
@@ -9,6 +9,9 @@
9
9
  module Pangrid
10
10
 
11
11
  class Text < Plugin
12
+
13
+ DESCRIPTION = "Basic text format (mostly for debugging)"
14
+
12
15
  def write(xw)
13
16
  across, down = xw.number
14
17
  rows = xw.to_array(:black => '#', :null => '.')
@@ -1,3 +1,3 @@
1
1
  module Pangrid
2
- VERSION='0.3.1'
2
+ VERSION='0.4.0'
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.3.1
4
+ version: 0.4.0
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-19 00:00:00.000000000 Z
11
+ date: 2019-07-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: martindemello@gmail.com
@@ -29,6 +29,8 @@ 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/exolve.rb
33
+ - lib/pangrid/plugins/json.rb
32
34
  - lib/pangrid/plugins/qxw.rb
33
35
  - lib/pangrid/plugins/reddit.rb
34
36
  - lib/pangrid/plugins/text.rb
@@ -56,8 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
58
  - !ruby/object:Gem::Version
57
59
  version: '0'
58
60
  requirements: []
59
- rubyforge_project:
60
- rubygems_version: 2.5.1
61
+ rubygems_version: 3.0.3
61
62
  signing_key:
62
63
  specification_version: 4
63
64
  summary: A crossword file format converter