Module: Mxrb::Uml::Support

Defined in:
lib/mxrb/uml/support.rb

Overview

Shared, deterministic escaping and identifier helpers for text formats.

Class Method Summary collapse

Class Method Details

.identifier(value, prefix: 'n') ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/mxrb/uml/support.rb', line 11

def identifier(value, prefix: 'n')
  raw = value.to_s
  body = raw.gsub(/[^A-Za-z0-9_]/, '_')
  body = prefix if body.empty?
  body = "#{prefix}_#{body}" unless body.match?(/\A[A-Za-z_]/)
  body += "_#{Digest::SHA256.hexdigest(raw)[0, 8]}" unless body == raw
  body
end

.mermaid_text(value) ⇒ Object



20
21
22
23
# File 'lib/mxrb/uml/support.rb', line 20

def mermaid_text(value)
  value.to_s.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;')
       .gsub('"', '&quot;').gsub(/[\r\n]+/, ' ')
end

.plantuml_text(value) ⇒ Object



25
26
27
# File 'lib/mxrb/uml/support.rb', line 25

def plantuml_text(value)
  value.to_s.gsub('\\') { '\\\\' }.gsub('"', '\\"').gsub(/[\r\n]+/, ' ')
end

.words(value) ⇒ Object



29
30
31
32
# File 'lib/mxrb/uml/support.rb', line 29

def words(value)
  value.to_s.delete_prefix('Microflows$').delete_suffix('Action')
       .gsub(/([a-z0-9])([A-Z])/, '\\1 \\2').tr('_', ' ').strip
end