class Jsm::Drawer::Digraph
list of all nodes
Attributes
state_machine[R]
Public Class Methods
new(state_machine)
click to toggle source
# File lib/jsm/drawer/digraph.rb, line 4 def initialize(state_machine) @state_machine = state_machine end
Public Instance Methods
nodes()
click to toggle source
list of all nodes
TODO: move it to different class(?)
# File lib/jsm/drawer/digraph.rb, line 10 def nodes unless @nodes events = state_machine.events.values @nodes = events.map{ |event| to_nodes(event) }.flatten end @nodes end
to_s()
click to toggle source
convert it to string that is compatible with api Graphviz
# File lib/jsm/drawer/digraph.rb, line 19 def to_s nodes.map(&:to_s).join(';') end
Private Instance Methods
to_nodes(event)
click to toggle source
convert transitions of event into nodes object return value is array e.g: [Jsm::Drawer::Node.new(:confirmed, :completed, :complete)]
# File lib/jsm/drawer/digraph.rb, line 28 def to_nodes(event) nodes = [] event.transitions.each do |transition| if transition.multiple_from? temp_nodes = transition.from.map{ |from| Jsm::Drawer::Node.new(from: from, to: transition.to, label: event.name) } else from = transition.from[0] # even only one it is still in array e.g: [:confirmed] temp_nodes = [Jsm::Drawer::Node.new(from: from, to: transition.to, label: event.name)] end nodes += temp_nodes end nodes end