Class: Flowchartviz

Inherits:
PxGraphViz
  • Object
show all
Defined in:
lib/flowchartviz.rb

Instance Method Summary collapse

Constructor Details

#initialize(s, truthlabels: %i(yes no), style: default_stylesheet(), delimiter: ' # ') ⇒ Flowchartviz

Returns a new instance of Flowchartviz.



12
13
14
15
16
17
18
19
20
21
22
23
24
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
# File 'lib/flowchartviz.rb', line 12

def initialize(s,truthlabels: %i(yes no), style: default_stylesheet(), 
               delimiter: ' # ')        
  
  @true, @false = truthlabels
  
  if s =~ /<?flowchartviz / then
    
    raw_fc = s.clone
    s2 = raw_fc.slice!(/<\?flowchartviz [^>]*\?>/)
    
    if s2 then
      
      attributes = %w(delimiter id).inject({}) do |r, keyword|
        found = s2[/(?<=#{keyword}=['"])[^'"]+/]
        found ? r.merge(keyword.to_sym => found) : r
      end
      
    end
    
    h = {delimiter: delimiter }.merge attributes || {}
    s = raw_fc

    delimiter = h[:delimiter]

  end    
  
  plaintext = scan(LineTree.new(s).to_a).flatten.compact.join("\n")
  
  schema = 'items[direction]/item[label, url, connection, shape]'    

raw_doc=<<EOF
<?polyrex schema='#{schema}' delimiter='#{delimiter}'?>
direction: TB
#{plaintext}
EOF

  super(raw_doc, style: style)
 
end