An observable type Set
. All type identifiers with corresponding Observers.
def Observer.observable()return OBSERVABLEend
Gets OBSERVABLE
. Returns the Set
reference.
def Observer.type(identifier = nil)return observable().include?(identifier)end
Predicate. Verifies an identifier is an observable identifier. Takes an argument identifier
. Expects any identifier. Returns true
in the case the argument is an observable type. Returns false
otherwise.
def Observer.changed(instance = nil)unless (type(instance.class()))return falseelse​k_o = kind_observer(instance)k_o_i = k_o.instance()casewhen k_o.equal?(NodeObserver)return (k_o_i.subject(instance) && k_o_i.changed_node(instance))end​end​end
Predicate. Verifies an instance's state. Takes an argument, instance
. Expects any instance type. Returns true
in the case the argument is an observable type, it is an Observer's subject, and its state changed. Returns false
otherwise.
def Observer.add_subject(subject = nil)​k_o = kind_observer(subject)k_o_i = k_o.instance()k_o_i.add(subject)return nil​end
Adds a subject in the appropriate Observer. Takes an observable instance argument, subject
. Adds the argument in the corresponding Observer's changed
Set
. Returns nil
.
def Observer.remove_subject(subject = nil)​k_o = kind_observer(subject)k_o_i = k_o.instance()k_o_i.remove(subject)return nil​end
Removes a subject in the appropriate Observer. Takes an observable instance argument, subject
. Removes the element from its changed
Set
. Returns nil
.
def Observer.notify(instance = nil)​ic_identifier = instance.class()if (type(ic_identifier))​k_o = kind_observer(instance)k_o.subject_changed(instance)return nil​elseraise(ArgumentError, "#{instance} is not an observable instance.")end​end
Notifies the appropriate Observer kind an instance's state changed. Takes an observable instance argument, instance
. Returns nil
. Raises an ArgumentError
in the case the argument is not an observable instance.
def Observer.kind_observer(instance = nil)​ic_identifier = instance.class()casewhen ic_identifier.equal?(Node)return NodeObserverelseraise(ArgumentError, "#{instance} is not an observable instance.")end​end
Gets the corresponding type's Observer. Takes an argument, instance
. Expects observable instances. In the case the instance's class is an observable type, returns its corresponding Observer. Otherwise, raises an ArgumentError
.