Libraries
Search…
Implementation
Class: Observer.

Constants

OBSERVABLE private

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

Attributes

Methods

Observer.observable()

1
def Observer.observable()
2
return OBSERVABLE
3
end
Copied!
Gets OBSERVABLE. Returns the Set reference.

Observer.type(identifier = nil)

1
def Observer.type(identifier = nil)
2
return observable().include?(identifier)
3
end
Copied!
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)

1
def Observer.changed(instance = nil)
2
3
unless (type(instance.class()))
4
return false
5
else
6
7
k_o = kind_observer(instance)
8
k_o_i = k_o.instance()
9
case
10
when k_o.equal?(NodeObserver)
11
return (k_o_i.subject(instance) && k_o_i.changed_node(instance))
12
end
13
14
end
15
16
end
Copied!
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)

1
def Observer.add_subject(subject = nil)
2
3
k_o = kind_observer(subject)
4
k_o_i = k_o.instance()
5
k_o_i.add(subject)
6
return nil
7
8
end
Copied!
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)

1
def Observer.remove_subject(subject = nil)
2
3
k_o = kind_observer(subject)
4
k_o_i = k_o.instance()
5
k_o_i.remove(subject)
6
return nil
7
8
end
Copied!
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)

1
def Observer.notify(instance = nil)
2
3
ic_identifier = instance.class()
4
if (type(ic_identifier))
5
6
k_o = kind_observer(instance)
7
k_o.subject_changed(instance)
8
return nil
9
10
else
11
raise(ArgumentError, "#{instance} is not an observable instance.")
12
end
13
14
end
Copied!
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

1
def Observer.kind_observer(instance = nil)
2
3
ic_identifier = instance.class()
4
case
5
when ic_identifier.equal?(Node)
6
return NodeObserver
7
else
8
raise(ArgumentError, "#{instance} is not an observable instance.")
9
end
10
11
end
Copied!
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

Last modified 1yr ago