module Sashite::CGN::Subject

Constants

PATTERN

Public Class Methods

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

  Ally.dump(io.fetch(:'...ally?')) + '<' +
  Actor.dump(io.fetch(:actor)) + '>' +
  State.dump(io.fetch(:state))
end
dumpable?(io) click to toggle source
# File lib/sashite/cgn/subject.rb, line 28
def self.dumpable? io
  io.is_a?(Hash) &&
  io.keys.sort == %i(...ally? actor state) &&
  Ally.dumpable?(io.fetch(:'...ally?')) &&
  Actor.dumpable?(io.fetch(:actor)) &&
  State.dumpable?(io.fetch(:state))
end
load(io) click to toggle source
# File lib/sashite/cgn/subject.rb, line 14
def self.load io
  raise ArgumentError unless loadable? io

  ally = Ally.load io.split('<').fetch(0)
  actor = Actor.load io.split('<').fetch(1).split('>').fetch(0)
  state = State.load io.split('>').fetch(1)

  {
    :"...ally?" => ally,
    actor: actor,
    state: state
  }
end
loadable?(io) click to toggle source
# File lib/sashite/cgn/subject.rb, line 10
def self.loadable? io
  !!io.match("^#{PATTERN}$")
end