0.0
No release in over 3 years
Graphomaton is a lightweight Ruby library for creating and visualizing finite state machines. It supports multiple output formats including SVG, Mermaid.js, GraphViz DOT, and PlantUML, making it easy to generate professional automaton diagrams.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 3.4
 Project Readme

Graphomaton Gem Version CI

A tiny Ruby library for generating finite state machine (automaton) diagrams in multiple formats: SVG, HTML (Mermaid.js), GraphViz (DOT), and PlantUML.

Image

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 in different formats
automaton.save_svg('output.svg')              # SVG format
automaton.save_html('output.html')            # HTML with Mermaid.js (requires internet)
automaton.save_dot('output.dot')              # GraphViz DOT format
automaton.save_plantuml('output.puml')        # PlantUML format

Output Formats

Graphomaton supports multiple output formats:

1. SVG (Native)

automaton.save_svg('diagram.svg', width = 800, height = 600)

Generates a standalone SVG file with custom rendering.

2. HTML (Mermaid.js)

automaton.save_html('diagram.html')

Generates an HTML file with embedded Mermaid.js state diagram. The diagram is rendered in the browser using Mermaid.js from CDN.

Note: Requires internet connection to load Mermaid.js from CDN. Does not work in offline environments.

3. GraphViz (DOT)

automaton.save_dot('diagram.dot')

Generates a DOT file that can be converted to images using GraphViz:

dot -Tpng diagram.dot -o diagram.png
dot -Tsvg diagram.dot -o diagram.svg
dot -Tpdf diagram.dot -o diagram.pdf

4. PlantUML

automaton.save_plantuml('diagram.puml')

Generates a PlantUML file that can be converted to images using PlantUML server or JAR:

# Using PlantUML JAR
java -jar plantuml.jar diagram.puml

# Using online server
curl -X POST --data-binary @diagram.puml https://www.plantuml.com/plantuml/png > diagram.png

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.