Class: CPEE::Transformation::Source::Mermaid

Inherits:
Object
  • Object
show all
Defined in:
lib/cpee/transformation/mermaid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Mermaid

{{{



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cpee/transformation/mermaid.rb', line 30

def initialize(text) #{{{
  Node.class_variable_set(:@@niceid,  {})

  @tree = Tree.new
  @start = nil

  @dataelements = {}
  @endpoints = {}
  @graph = Graph.new

  extract_nodelink(text)

  if @start.nil?
    @traces = Traces.new [[]]
  else
    @traces = Traces.new [[@start]]
  end
end

Instance Attribute Details

#dataelementsObject (readonly)

Returns the value of attribute dataelements.



28
29
30
# File 'lib/cpee/transformation/mermaid.rb', line 28

def dataelements
  @dataelements
end

#endpointsObject (readonly)

Returns the value of attribute endpoints.



28
29
30
# File 'lib/cpee/transformation/mermaid.rb', line 28

def endpoints
  @endpoints
end

#graphObject (readonly)

Returns the value of attribute graph.



28
29
30
# File 'lib/cpee/transformation/mermaid.rb', line 28

def graph
  @graph
end

#startObject (readonly)

Returns the value of attribute start.



28
29
30
# File 'lib/cpee/transformation/mermaid.rb', line 28

def start
  @start
end

#tracesObject (readonly)

Returns the value of attribute traces.



28
29
30
# File 'lib/cpee/transformation/mermaid.rb', line 28

def traces
  @traces
end

#treeObject (readonly)

Returns the value of attribute tree.



28
29
30
# File 'lib/cpee/transformation/mermaid.rb', line 28

def tree
  @tree
end

Instance Method Details

{{{



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/cpee/transformation/mermaid.rb', line 65

def extract_nodelink(text) #{{{
  first = nil
  text.each_line do |line|
    if line =~ /-->/
      a = line.strip.split(/-->\s*(\|([^|]+)\|)?/)
      if a.length == 2
        l, r = a
      else
        l, _, c, r = a
      end

      lid, ltype, llabel = l.strip.split(':',3)
      rid, rtype, rlabel = r.strip.split(':',3)

      ltype = 'task' if ltype.nil?
      rtype = 'task' if rtype.nil?

      if lid =~ /^([a-zA-Z\d]+)(\[([^\]]+)\])/
        lid = $1
        llabel = $3
      end

      if rid =~ /^([a-zA-Z\d]+)(\[([^\]]+)\])/
        rid = $1
        rlabel = $3
      end

      llabel = '' if llabel.nil?
      rlabel = '' if rlabel.nil?
      llabel.sub(/^'/,'')
      llabel.sub(/'$/,'')
      llabel.sub(/^"/,'')
      llabel.sub(/"$/,'')
      rlabel.sub(/^'/,'')
      rlabel.sub(/'$/,'')
      rlabel.sub(/^"/,'')
      rlabel.sub(/"$/,'')

							# every line contains a link
							@graph.add_link Link.new(lid, rid, c.nil? ? nil : c.to_s.gsub(/(^"|"$)/, ''))

      n1 = Node.new(0,lid,map_nodes(ltype),llabel.sub(/^\(/,'').sub(/\)$/,''),0,1)
      n2 = Node.new(0,rid,map_nodes(rtype),rlabel.sub(/^\(/,'').sub(/\)$/,''),1,0)

      @graph.add_node n1, :outgoing
      @graph.add_node n2, :incoming

first = n1 if first.nil?
      @start = n1 if n1.type == :startEvent && @start.nil?
    end
    @start = first if @start.nil?
  end
end