class Observer

Observer. @class_description

An Observer library implementation. Implements the Observer library
interface.

Observer. @class_description

An Observer library implementation. Implements the Observer library
interface.

Constants

OBSERVABLE

Private constants.

VERSION

Public Class Methods

add_subject(subject = nil) click to toggle source

self.add_subject(subject = nil). @description

Adds a subject in the appropriate Observer.

@param subject [.]

Any observable instance.

@return [NilClass]

nil.
# File lib/observer_impl.rb, line 66
def self.add_subject(subject = nil)

  k_o   = kind_observer(subject)
  k_o_i = k_o.instance()
  k_o_i.add(subject)
  return nil

end
changed(instance = nil) click to toggle source

self.changed(instance = nil). @description

Verifies an instance's state.

@param instance [.]

Any instance.

@return [TrueClass, FalseClass]

True in the case the argument is an observable type, it is an
Observer's subject, and its state changed. False otherwise.
# File lib/observer_impl.rb, line 42
def self.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
notify(instance = nil) click to toggle source

self.notify(instance = nil). @description

Notifies the appropriate Observer kind an instance's state changed.

@param instance [.]

An observable instance.

@return [NilClass]

nil.

@raise [ArgumentError]

In the case 'instance' is not an observable instance.
# File lib/observer_impl.rb, line 100
def self.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
observable() click to toggle source

self.observable(). @description

Gets OBSERVABLE.

@return [Set]

OBSERVABLE's reference.
# File lib/observer_impl.rb, line 19
def self.observable()
  return OBSERVABLE
end
remove_subject(subject = nil) click to toggle source

self.remove_subject(subject = nil). @description

Removes a subject in the appropriate Observer.

@param subject [.]

Any observable instance.

@return [NilClass]

nil.
# File lib/observer_impl.rb, line 82
def self.remove_subject(subject = nil)

  k_o   = kind_observer(subject)
  k_o_i = k_o.instance()
  k_o_i.remove(subject)
  return nil

end
type(identifier = nil) click to toggle source

self.type(identifier = nil). @description

Predicate. Verifies an identifier is an observable identifier.

@param identifier [.]

Any identifier.

@return [TrueClass, FalseClass]

True in the case the identifier is an observable type. False otherwise.
# File lib/observer_impl.rb, line 30
def self.type(identifier = nil)
  return observable().include?(identifier)
end

Private Class Methods

kind_observer(instance = nil) click to toggle source

self.kind_observer(instance = nil). @description

Gets the corresponding type's observer.

@param instance [.]

Any observable instance.

@return [.]

The argument's corresponding observer identifier.

@raise [ArgumentError]

In the case the instance is not an observable instance.
# File lib/observer_impl.rb, line 124
def self.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