A tiny Ruby library for generating finite state machine (automaton) diagrams as SVG.
Installation
Add this line to your application's Gemfile:
gem 'graphomaton'
And then execute:
bundle install
Or install it yourself as:
gem install graphomaton
Usage
require 'graphomaton'
# Create a DFA that accepts strings ending with 'ab'
automaton = Graphomaton.new
# Add states
automaton.add_state('q0')
automaton.add_state('q1')
automaton.add_state('q2')
# Set initial and final states
automaton.set_initial('q0')
automaton.add_final('q2')
# Add transitions
automaton.add_transition('q0', 'q1', 'a')
automaton.add_transition('q1', 'q2', 'b')
automaton.add_transition('q0', 'q0', 'b')
automaton.add_transition('q1', 'q0', 'a')
automaton.add_transition('q2', 'q0', 'b')
automaton.add_transition('q2', 'q1', 'a')
# Save as SVG
automaton.save_svg('output.svg')
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ydah/graphomaton.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Graphomaton project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.