simplificator-fsm 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/VERSION.yml +1 -1
  2. data/lib/fsm/machine.rb +18 -0
  3. metadata +2 -2
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 2
4
- :patch: 2
4
+ :patch: 3
data/lib/fsm/machine.rb CHANGED
@@ -79,6 +79,24 @@ module FSM
79
79
  state
80
80
  end
81
81
 
82
+ def to_dot
83
+ dots = self.transitions.map do |transition|
84
+ " #{transition.from.name} -> #{transition.to.name}"
85
+ end
86
+ "digraph FSM {\n#{dots.join(";\n")}\n}"
87
+ end
88
+
89
+ def dot(options = {})
90
+ format = options[:format] || :png
91
+ extension = options[:extension] || format
92
+ file_name = options[:outfile] || "#{@target_class.name.downcase}.#{extension}"
93
+ cmd = "dot -T#{format} -o#{file_name}"
94
+ IO.popen cmd, 'w' do |io|
95
+ io.write to_dot
96
+ end
97
+ raise 'dot failed' unless $?.success?
98
+ end
99
+
82
100
  private
83
101
 
84
102
  # defines a transition method on the target class.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplificator-fsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - simplificator
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-19 00:00:00 -07:00
12
+ date: 2009-05-25 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15