Class: StateFu::Plotter
Constant Summary collapse
- OUTPUT_HELPER =
Module.new do def save! Tempfile.new(['state_fu_graph','.dot']) do |fh| fh.write( self ) end.path end def save_as( filename ) File.open(filename, 'w') { |fh| fh.write( self ) } end def save_png(filename) raise NotImplementedError # dot graph.dot -Tpng -O end end
Instance Attribute Summary collapse
-
#dot ⇒ Object
readonly
Returns the value of attribute dot.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#machine ⇒ Object
readonly
Returns the value of attribute machine.
-
#states ⇒ Object
readonly
Returns the value of attribute states.
Instance Method Summary collapse
- #generate ⇒ Object
- #generate_dot! ⇒ Object
-
#initialize(machine, options = {}) ⇒ Plotter
constructor
A new instance of Plotter.
- #output ⇒ Object
Constructor Details
#initialize(machine, options = {}) ⇒ Plotter
Returns a new instance of Plotter.
30 31 32 33 34 35 36 37 |
# File 'lib/support/plotter.rb', line 30 def initialize( machine, ={} ) raise RuntimeError, machine.class.to_s unless machine.is_a?(StateFu::Machine) @machine = machine @options = .symbolize_keys! @states = {} @events = {} # generate end |
Instance Attribute Details
#dot ⇒ Object (readonly)
Returns the value of attribute dot.
5 6 7 |
# File 'lib/support/plotter.rb', line 5 def dot @dot end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
5 6 7 |
# File 'lib/support/plotter.rb', line 5 def events @events end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
5 6 7 |
# File 'lib/support/plotter.rb', line 5 def graph @graph end |
#machine ⇒ Object (readonly)
Returns the value of attribute machine.
5 6 7 |
# File 'lib/support/plotter.rb', line 5 def machine @machine end |
#states ⇒ Object (readonly)
Returns the value of attribute states.
5 6 7 |
# File 'lib/support/plotter.rb', line 5 def states @states end |
Instance Method Details
#generate ⇒ Object
39 40 41 |
# File 'lib/support/plotter.rb', line 39 def generate @dot ||= generate_dot!.extend( OUTPUT_HELPER ) end |
#generate_dot! ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/support/plotter.rb', line 43 def generate_dot! @graph = Vizier::Graph.new(:state_machine) do |g| g.node :shape => 'doublecircle' machine.state_names.map.each do |s| @states[s] = g.add_node(s.to_s) end machine.events.map.each do |e| e.origins.map(&:name).each do |from| e.targets.map(&:name).each do |to| g.connect( @states[from], @states[to], :label => e.name.to_s ) end end # @events[s] = g.add_node(s.to_s) end end @graph.generate! end |
#output ⇒ Object
26 27 28 |
# File 'lib/support/plotter.rb', line 26 def output generate end |