Class: StateMachines::State

Inherits:
Object
  • Object
show all
Defined in:
lib/state_machines/graphviz/monkeypatch.rb

Instance Method Summary collapse

Instance Method Details

#draw(graph, options = {}) ⇒ Object

Draws a representation of this state on the given machine. This will create a new node on the graph with the following properties:

  • label - The human-friendly description of the state.

  • width - The width of the node. Always 1.

  • height - The height of the node. Always 1.

  • shape - The actual shape of the node. If the state is a final state, then “doublecircle”, otherwise “ellipse”.

Configuration options:

  • :human_name - Whether to use the state’s human name for the node’s label that gets drawn on the graph



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/state_machines/graphviz/monkeypatch.rb', line 85

def draw(graph, options = {})
  node = graph.add_nodes(name ? name.to_s : 'nil',
                         :label => description(options),
                         :width => '1',
                         :height => '1',
                         :shape => final? ? 'doublecircle' : 'ellipse'
  )

  # Add open arrow for initial state
  graph.add_edges(graph.add_nodes('starting_state', :shape => 'point'), node) if initial?

  true
end