Class: Graphomaton::Exporters::Plantuml
- Inherits:
-
Object
- Object
- Graphomaton::Exporters::Plantuml
- Includes:
- Graphomaton::ExporterIntrospection
- Defined in:
- lib/graphomaton/exporters/plantuml.rb
Constant Summary collapse
- DEFAULT_DIRECTION =
:lr- DEFAULT_NOTES =
false- DIRECTION_OPTIONS =
%i[lr tb rl bt].freeze
- PSEUDOSTATE_TYPES =
%i[choice fork join].freeze
- RESERVED_IDENTIFIERS =
%w[state note skinparam hide left right top bottom direction as of].freeze
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(automaton, direction: DEFAULT_DIRECTION, theme: nil, notes: DEFAULT_NOTES) ⇒ Plantuml
constructor
A new instance of Plantuml.
Methods included from Graphomaton::ExporterIntrospection
Constructor Details
#initialize(automaton, direction: DEFAULT_DIRECTION, theme: nil, notes: DEFAULT_NOTES) ⇒ Plantuml
Returns a new instance of Plantuml.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/graphomaton/exporters/plantuml.rb', line 13 def initialize(automaton, direction: DEFAULT_DIRECTION, theme: nil, notes: DEFAULT_NOTES) @automaton = automaton @direction = resolve_direction(direction) @theme = resolve_theme(theme) @notes = notes @identifiers = IdentifierAllocator.new(reserved: RESERVED_IDENTIFIERS) @state_names = allocate_state_names @hierarchy_usable = @automaton.validation_diagnostics.none? do |diagnostic| diagnostic.code == 'invalid-state-hierarchy' end end |
Instance Method Details
#export ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/graphomaton/exporters/plantuml.rb', line 25 def export lines = ['@startuml'] lines << 'hide empty description' lines << direction_keyword lines.concat(theme_lines) if @theme lines.concat(state_alias_lines) lines.concat(pseudostate_lines) lines.concat(composite_state_lines) lines.concat(state_group_lines) lines << '' if @automaton.initial_state lines << "[*] --> #{state_name(@automaton.initial_state)}" end @automaton.transition_records.each do |trans| from = state_name(trans[:from]) to = state_name(trans[:to]) label = escape_label(trans[:label]) lines << "#{from} --> #{to} : #{label}" end @automaton.final_states.each do |state| lines << "#{state_name(state)} --> [*]" end lines.concat(state_note_lines) if @notes lines << '' lines << '@enduml' "#{lines.join("\n")}\n" end |