module Sashite::CGN::Object

Constants

PATTERN

Public Class Methods

dump(io) click to toggle source
# File lib/sashite/cgn/object.rb, line 35
def self.dump io
  raise ArgumentError unless dumpable? io

  Square.dump(io.fetch(:src_square)) + '~' +
  Square.dump(io.fetch(:dst_square)) + '%' +
  PromotableIntoActors.dump(io.fetch(:promotable_into_actors))
end
dumpable?(io) click to toggle source
# File lib/sashite/cgn/object.rb, line 27
def self.dumpable? io
  io.is_a?(Hash) &&
  io.keys.sort == %i(dst_square promotable_into_actors src_square) &&
  Square.dumpable?(io.fetch(:dst_square)) &&
  Square.dumpable?(io.fetch(:src_square)) &&
  PromotableIntoActors.dumpable?(io.fetch(:promotable_into_actors))
end
load(io) click to toggle source
# File lib/sashite/cgn/object.rb, line 13
def self.load io
  raise ArgumentError unless loadable? io

  src_square = Square.load io.split('~').fetch 0
  dst_square = Square.load io.split('~').fetch(1).split('%').fetch 0
  promotable_into_actors = PromotableIntoActors.load io.split('%').fetch 1

  {
    src_square: src_square,
    dst_square: dst_square,
    promotable_into_actors: promotable_into_actors
  }
end
loadable?(io) click to toggle source
# File lib/sashite/cgn/object.rb, line 9
def self.loadable? io
  !!io.match("^#{PATTERN}$")
end