Class: GraphVizML

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ GraphVizML

Returns a new instance of GraphVizML.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/graphvizml.rb', line 15

def initialize(obj)
  
  xml = if obj.is_a? String then
          
    File.read filename=obj
    
  elsif obj.is_a? Rexle or obj.is_a? Rexle::Element
    
    obj.xml

  end    
  
  doc = Domle.new(xml)    

  # check if the root node is gvml or nodes
  @g = if doc.root.name == 'gvml' then
    build_from_gvml doc
  elsif doc.root.name == 'nodes'
    build_from_nodes doc
  end

end

Instance Attribute Details

#gObject (readonly)

Returns the value of attribute g.



13
14
15
# File 'lib/graphvizml.rb', line 13

def g
  @g
end

Instance Method Details

#to_dotObject



38
39
40
# File 'lib/graphvizml.rb', line 38

def to_dot()
  @g.to_dot
end

#to_pngObject

returns a PNG blob



44
45
46
47
48
# File 'lib/graphvizml.rb', line 44

def to_png()
  f = Tempfile.new('graphvizml')
  Graphviz::output(@g, output_format: 'png', path: f.path)
  File.read f.path
end

#to_svgObject

returns an SVG blob



52
53
54
55
56
# File 'lib/graphvizml.rb', line 52

def to_svg()
  f = Tempfile.new('graphvizml')
  Graphviz::output(@g, format: 'svg', path: f.path)
  File.read f.path
end

#write(filename) ⇒ Object



58
59
60
# File 'lib/graphvizml.rb', line 58

def write(filename)
  Graphviz::output(@g, :path => filename)
end