module Sashite::CGN::State
Constants
- PATTERN
Public Class Methods
dump(io)
click to toggle source
# File lib/sashite/cgn/state.rb, line 32 def self.dump io raise ArgumentError unless dumpable? io LastMovedActor.dump(io.fetch(:'...last_moved_actor?')) + '&' + PreviousMovesCounter.dump(io.fetch(:'...previous_moves_counter')) end
dumpable?(io)
click to toggle source
# File lib/sashite/cgn/state.rb, line 25 def self.dumpable? io io.is_a?(Hash) && io.keys.sort == %i(...last_moved_actor? ...previous_moves_counter) && LastMovedActor.dumpable?(io.fetch(:'...last_moved_actor?')) && PreviousMovesCounter.dumpable?(io.fetch(:'...previous_moves_counter')) end
load(io)
click to toggle source
# File lib/sashite/cgn/state.rb, line 13 def self.load io raise ArgumentError unless loadable? io last_moved_actor = LastMovedActor.load io.split('&').fetch(0) previous_moves_counter = PreviousMovesCounter.load io.split('&').fetch(1) { :"...last_moved_actor?" => last_moved_actor, :"...previous_moves_counter" => previous_moves_counter } end
loadable?(io)
click to toggle source
# File lib/sashite/cgn/state.rb, line 9 def self.loadable? io !!io.match("^#{PATTERN}$") end