Implementation

Class: Observer.

Constants

OBSERVABLE private

An observable type Set. All type identifiers with corresponding Observers.

Attributes

Methods

Observer.observable()

def Observer.observable()
return OBSERVABLE
end

Gets OBSERVABLE. Returns the Set reference.

Observer.type(identifier = nil)

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.

Observer.changed(instance = nil)

def Observer.changed(instance = nil)
unless (type(instance.class()))
return false
else
k_o = kind_observer(instance)
k_o_i = k_o.instance()
case
when 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.

Observer.add_subject(subject = nil)

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.

Observer.remove_subject(subject = 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.

Observer.notify(instance = 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
else
raise(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.

Observer.kind_observer(instance = nil) private

def Observer.kind_observer(instance = nil)
ic_identifier = instance.class()
case
when ic_identifier.equal?(Node)
return NodeObserver
else
raise(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.

Observable.new() private, undefined