Method: Gnuplot.plot_to

Defined in:
lib/gnuplot.rb

.plot_to(file, persist = false, *args, &block) ⇒ Object

If file is a file name that has a Gnuplot.terminal associated with it, the GNUPLOT process’s terminal will be set accordingly and its output redirected to file.

If file is an IO object or doesn’t have a terminal associated with it, the GNUPLOT process’s output will simply be written to file.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/gnuplot.rb', line 69

def plot_to(file, persist = false, *args, &block)
  io, file = file, nil if file.respond_to?(:write)

  if file and term = terminal(File.extname(file))
    plot(persist, *args) { |plot|
      block[plot]

      plot.terminal term unless plot[:terminal] || plot[:term]
      plot.output file.to_s unless plot[:output] || plot[:out]
    }
  else
    begin
      io ||= File.open(file, 'w')
      Plot.new(io, *args, &block)
    ensure
      io.close if file && io
    end
  end
end