Class: GraphVizML
- Inherits:
-
Object
- Object
- GraphVizML
- Defined in:
- lib/graphvizml.rb
Instance Attribute Summary collapse
-
#g ⇒ Object
readonly
Returns the value of attribute g.
Instance Method Summary collapse
-
#initialize(obj) ⇒ GraphVizML
constructor
A new instance of GraphVizML.
- #to_dot ⇒ Object
-
#to_png ⇒ Object
returns a PNG blob.
-
#to_svg ⇒ Object
returns an SVG blob.
- #write(filename) ⇒ Object
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
#g ⇒ Object (readonly)
Returns the value of attribute g.
13 14 15 |
# File 'lib/graphvizml.rb', line 13 def g @g end |
Instance Method Details
#to_dot ⇒ Object
38 39 40 |
# File 'lib/graphvizml.rb', line 38 def to_dot() @g.to_dot end |
#to_png ⇒ Object
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_svg ⇒ Object
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 |