Class: Dot2Ruby

Inherits:
Object show all
Includes:
GraphViz::Utils
Defined in:
lib/graphviz/dot2ruby.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from GraphViz::Utils

#find_executable, #output_and_errors_from_command, #output_from_command

Constructor Details

#initialize(xGVPath, xOutFile, xOutFormat = nil) ⇒ Dot2Ruby

:nodoc:



24
25
26
27
28
29
30
31
32
33
# File 'lib/graphviz/dot2ruby.rb', line 24

def initialize( xGVPath, xOutFile, xOutFormat = nil ) #:nodoc:
  paths = (xGVPath.nil?) ? [] : [xGVPath]
  @xGvprPath = find_executable( 'gvpr', paths )
  if(@xGvprPath.nil?)
    raise Exception, "GraphViz is not installed. Please be sure that 'gvpr' is on the search path'"
  end
  @xOutFile = xOutFile
  @xOutFormat = xOutFormat || "_"
  @gvprScript = GraphViz::Ext.find( "dot2ruby.g" )
end

Instance Method Details

#eval(xFile) ⇒ Object

:nodoc:



47
48
49
50
51
52
# File 'lib/graphviz/dot2ruby.rb', line 47

def eval( xFile ) #:nodoc:
  xCmd = [@xGvprPath, '-f', @gvprScript, '-a', '-', xFile]
  xOutput = output_from_command( xCmd )
  instance_eval(xOutput)
  return @_graph_eval
end

#eval_string(data) ⇒ Object

:nodoc:



54
55
56
57
58
59
60
61
# File 'lib/graphviz/dot2ruby.rb', line 54

def eval_string( data ) #:nodoc:
  t = Tempfile::open( File.basename(__FILE__) )
  t.print( data )
  t.close
  result = self.eval(t.path)
  t.close
  return result
end

#run(xFile) ⇒ Object

:nodoc:



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/graphviz/dot2ruby.rb', line 35

def run( xFile ) #:nodoc:
  xCmd = [@xGvprPath, '-f', @gvprScript, '-a', @xOutFormat, xFile]
  xOutput = output_from_command( xCmd )
  if @xOutFile.nil?
    puts xOutput
  else
    File.open( @xOutFile, "w" ) do |io|
      io.print xOutput
    end
  end
end