Module: Pangrid::AcrossLiteUtils

Included in:
AcrossLiteBinary, AcrossLiteText
Defined in:
lib/pangrid/plugins/acrosslite.rb

Instance Method Summary collapse

Instance Method Details

#empty_fill(xw) ⇒ Object

| solution = Cell[] -> String



63
64
65
66
67
68
# File 'lib/pangrid/plugins/acrosslite.rb', line 63

def empty_fill(xw)
  # when converting from another format -> binary we won't typically have fill
  # information, since that is an internal property of the acrosslite player
  grid = xw.to_array(FILL_CHARS) {|c| '-'}
  grid.map(&:join).join
end

#pack_solution(xw) ⇒ Object

| solution = Cell[] -> String



56
57
58
59
60
# File 'lib/pangrid/plugins/acrosslite.rb', line 56

def pack_solution(xw)
  # acrosslite doesn't support non-rectangular grids, so map null squares to
  # black too
  xw.to_array(GRID_CHARS).map(&:join).join
end

#unpack_solution(xw, s) ⇒ Object

String -> Cell[]



49
50
51
52
53
# File 'lib/pangrid/plugins/acrosslite.rb', line 49

def unpack_solution(xw, s)
  s.each_char.map {|c|
    Cell.new(:solution => c == '.' ? :black : c)
  }.each_slice(xw.width).to_a
end