Class: EndState::Graph
- Inherits:
-
GraphViz
- Object
- GraphViz
- EndState::Graph
- Defined in:
- lib/end_state/graph.rb
Instance Attribute Summary collapse
-
#event_labels ⇒ Object
readonly
Returns the value of attribute event_labels.
-
#machine ⇒ Object
readonly
Returns the value of attribute machine.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(machine, event_labels = true) ⇒ Graph
constructor
A new instance of Graph.
Constructor Details
#initialize(machine, event_labels = true) ⇒ Graph
Returns a new instance of Graph.
5 6 7 8 9 10 |
# File 'lib/end_state/graph.rb', line 5 def initialize(machine, event_labels=true) @machine = machine @nodes = {} @event_labels = event_labels super machine.name.to_sym end |
Instance Attribute Details
#event_labels ⇒ Object (readonly)
Returns the value of attribute event_labels.
3 4 5 |
# File 'lib/end_state/graph.rb', line 3 def event_labels @event_labels end |
#machine ⇒ Object (readonly)
Returns the value of attribute machine.
3 4 5 |
# File 'lib/end_state/graph.rb', line 3 def machine @machine end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
3 4 5 |
# File 'lib/end_state/graph.rb', line 3 def nodes @nodes end |
Instance Method Details
#draw ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/end_state/graph.rb', line 12 def draw machine.transitions.keys.each do |t| left, right = t.to_a.flatten nodes[left] ||= add_node(left.to_s) nodes[right] ||= add_node(right.to_s) edge = add_edge nodes[left], nodes[right] if event_labels event = machine.events.detect do |event, transition| transition.include? t end edge[:label] = event.first.to_s if event end end self end |