Method: GnuplotRB::Plottable#to_specific_term

Defined in:
lib/gnuplotrb/mixins/plottable.rb

#to_specific_term(terminal, path = nil, **options) ⇒ Object

Output plot to specific terminal (possibly some file). Explicit use should be avoided. This method is called from #method_missing when it handles method names like #to_png(options).

Examples:

## plot here may be Plot, Splot, Multiplot or any other plottable class
plot.to_png('./result.png', size: [300, 500])
contents = plot.to_svg(size: [100, 100])
plot.to_dumb('./result.txt', size: [30, 15])

Parameters:

  • trminal (String)

    terminal name (‘png’, ‘svg’ etc)

  • path (String) (defaults to: nil)

    path to output file, if none given it will output to temp file and then read it and return binary contents of file

  • options (Hash)

    used in #plot



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/gnuplotrb/mixins/plottable.rb', line 109

def to_specific_term(terminal, path = nil, **options)
  if path
    result = plot(term: [terminal, options], output: path)
  else
    path = Dir::Tmpname.make_tmpname(terminal, 0)
    plot(term: [terminal, options], output: path)
    result = File.binread(path)
    File.delete(path)
  end
  result
end