Class: Lifelike::Grid::GridSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/lifelike/grid.rb

Constant Summary collapse

ROW_DELIMITER =
"\n"
CELL_DELIMITER =
''

Class Method Summary collapse

Class Method Details

.dump(grid) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/lifelike/grid.rb', line 68

def self.dump(grid)
  grid.to_a.map do |row|
    row.map do |cell|
      yield(cell)
    end.join(CELL_DELIMITER)
  end.join(ROW_DELIMITER)
end

.load(string) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/lifelike/grid.rb', line 58

def self.load(string)
  Grid.new(
    string.split(ROW_DELIMITER).map do |row_string|
      row_string.split(CELL_DELIMITER).map do |char|
        yield(char)
      end
    end
  )
end