2018-03-09 16:49:47 -05:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'json'
|
|
|
|
|
|
|
|
Dir.glob('./tests/ref/**/grid.json').each do |path|
|
2018-05-19 14:18:37 -04:00
|
|
|
puts "Migrating #{path}"
|
|
|
|
|
2018-03-09 16:49:47 -05:00
|
|
|
# Read contents
|
|
|
|
s = File.open(path) { |f| f.read }
|
|
|
|
|
|
|
|
# Parse
|
|
|
|
grid = JSON.parse(s)
|
|
|
|
|
2018-05-19 14:18:37 -04:00
|
|
|
# Normalize Storage serialization
|
|
|
|
if grid['raw'].is_a? Array
|
|
|
|
grid['raw'] = {
|
|
|
|
'inner' => grid['raw'][0],
|
|
|
|
'zero' => grid['raw'][1],
|
|
|
|
'visible_lines' => grid['raw'][2]
|
|
|
|
}
|
|
|
|
end
|
2018-03-09 16:49:47 -05:00
|
|
|
|
2018-05-19 14:18:37 -04:00
|
|
|
# Migrate Row serialization
|
|
|
|
grid['raw']['inner'].map! do |row|
|
|
|
|
if row.is_a? Hash
|
|
|
|
row
|
|
|
|
else
|
|
|
|
{ inner: row, occ: row.length }
|
|
|
|
end
|
|
|
|
end
|
2018-03-09 16:49:47 -05:00
|
|
|
|
|
|
|
# Write updated grid
|
|
|
|
File.open(path, 'w') { |f| f << JSON.generate(grid) }
|
|
|
|
end
|