Class: Skeem::SkmElementVisitor
- Inherits:
-
Object
- Object
- Skeem::SkmElementVisitor
- Defined in:
- lib/skeem/element_visitor.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Link to the root element to visit.
-
#runtime ⇒ Object
readonly
Returns the value of attribute runtime.
-
#subscribers ⇒ Object
readonly
List of objects that subscribed to the visit event notification.
Instance Method Summary collapse
-
#initialize(aRoot) ⇒ SkmElementVisitor
constructor
Build a visitor for the given root.
-
#start(aRuntime) ⇒ Object
The signal to begin the visit of the root.
-
#subscribe(aSubscriber) ⇒ Object
Add a subscriber for the visit event notifications.
-
#unsubscribe(aSubscriber) ⇒ Object
Remove the given object from the subscription list.
- #visit_compound_datum(aCompoundDatum) ⇒ Object
-
#visit_empty_list(anEmptyList) ⇒ Object
Visit event.
- #visit_pair(aPair) ⇒ Object
-
#visit_simple_datum(aSimpleDatum) ⇒ Object
Visit event.
Constructor Details
#initialize(aRoot) ⇒ SkmElementVisitor
Build a visitor for the given root.
15 16 17 18 19 20 |
# File 'lib/skeem/element_visitor.rb', line 15 def initialize(aRoot) raise StandardError if aRoot.nil? @root = aRoot @subscribers = [] end |
Instance Attribute Details
#root ⇒ Object (readonly)
Link to the root element to visit
6 7 8 |
# File 'lib/skeem/element_visitor.rb', line 6 def root @root end |
#runtime ⇒ Object (readonly)
Returns the value of attribute runtime.
11 12 13 |
# File 'lib/skeem/element_visitor.rb', line 11 def runtime @runtime end |
#subscribers ⇒ Object (readonly)
List of objects that subscribed to the visit event notification.
9 10 11 |
# File 'lib/skeem/element_visitor.rb', line 9 def subscribers @subscribers end |
Instance Method Details
#start(aRuntime) ⇒ Object
The signal to begin the visit of the root.
36 37 38 39 |
# File 'lib/skeem/element_visitor.rb', line 36 def start(aRuntime) @runtime = aRuntime root.accept(self) end |
#subscribe(aSubscriber) ⇒ Object
Add a subscriber for the visit event notifications.
24 25 26 |
# File 'lib/skeem/element_visitor.rb', line 24 def subscribe(aSubscriber) subscribers << aSubscriber end |
#unsubscribe(aSubscriber) ⇒ Object
Remove the given object from the subscription list. The object won't be notified of visit events.
31 32 33 |
# File 'lib/skeem/element_visitor.rb', line 31 def unsubscribe(aSubscriber) subscribers.delete_if { |entry| entry == aSubscriber } end |
#visit_compound_datum(aCompoundDatum) ⇒ Object
49 50 51 52 53 |
# File 'lib/skeem/element_visitor.rb', line 49 def visit_compound_datum(aCompoundDatum) broadcast(:before_compound_datum, aCompoundDatum) traverse_children(aCompoundDatum) broadcast(:after_compound_datum, aCompoundDatum) end |
#visit_empty_list(anEmptyList) ⇒ Object
Visit event. The visitor is visiting the given empty list object.
58 59 60 61 |
# File 'lib/skeem/element_visitor.rb', line 58 def visit_empty_list(anEmptyList) broadcast(:before_empty_list, anEmptyList) broadcast(:after_empty_list, anEmptyList) end |
#visit_pair(aPair) ⇒ Object
63 64 65 66 67 |
# File 'lib/skeem/element_visitor.rb', line 63 def visit_pair(aPair) broadcast(:before_pair, aPair) traverse_car_cdr(aPair) broadcast(:after_pair, aPair) end |
#visit_simple_datum(aSimpleDatum) ⇒ Object
Visit event. The visitor is visiting the given simple datum object.
44 45 46 47 |
# File 'lib/skeem/element_visitor.rb', line 44 def visit_simple_datum(aSimpleDatum) broadcast(:before_simple_datum, aSimpleDatum) broadcast(:after_simple_datum, aSimpleDatum) end |