Class: Pangrid::Text
Constant Summary collapse
- DESCRIPTION =
"Basic text format (mostly for debugging)"
Constants inherited from Plugin
Plugin::FAILED, Plugin::MISSING_DEPS, Plugin::REGISTRY
Instance Method Summary collapse
- #format_clues(numbers, clues, indent) ⇒ Object
-
#read_grid(data) ⇒ Object
rename to ‘read’ when this is complete.
- #write(xw) ⇒ Object
Methods inherited from Plugin
class_to_name, get, inherited, list_all, load_all, load_plugin
Methods included from PluginUtils
Instance Method Details
#format_clues(numbers, clues, indent) ⇒ Object
32 33 34 |
# File 'lib/pangrid/plugins/text.rb', line 32 def format_clues(numbers, clues, indent) numbers.zip(clues).map {|n, c| " "*indent + "#{n.to_s.rjust(2)}. #{c}"}.join("\n") end |
#read_grid(data) ⇒ Object
rename to ‘read’ when this is complete
25 26 27 28 29 30 |
# File 'lib/pangrid/plugins/text.rb', line 25 def read_grid(data) s = data.each_line.map(&:strip) m = s[0].match(/^Grid (\d+) (\d+)$/) check("Grid line missing") { m } xw.height, xw.width = m[1].to_i, m[2].to_i end |
#write(xw) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/pangrid/plugins/text.rb', line 15 def write(xw) across, down = xw.number rows = xw.to_array(:black => '#', :null => '.') grid = rows.map(&:join).join("\n") + "\n" ac = "Across:\n\n" + format_clues(across, xw.across_clues, 2) dn = "Down:\n\n" + format_clues(down, xw.down_clues, 2) grid + "\n" + ac + "\n\n" + dn + "\n" end |