Module | Gnuplot |
In: |
lib/gnuplot.rb
|
Find the path to the gnuplot executable. The name of the executable can be specified using the RB_GNUPLOT environment variable but will default to the command ‘gnuplot’.
persist [bool] Add the persist flag to the gnuplot executable
Return the path to the gnuplot executable or nil if one cannot be found.
# File lib/gnuplot.rb, line 43 43: def Gnuplot.gnuplot( persist = true ) 44: cmd = which( ENV['RB_GNUPLOT'] || 'gnuplot' ) 45: cmd += " -persist" if persist 46: cmd 47: end
Open a gnuplot process that exists in the current PATH. If the persist flag is true then the -persist flag is added to the command line. The path to the gnuplot executable is determined using the ‘which’ command.
See the gnuplot documentation for information on the persist flag.
todo Add a method to pass the gnuplot path to the function.
# File lib/gnuplot.rb, line 57 57: def Gnuplot.open( persist=true ) 58: cmd = Gnuplot.gnuplot( persist ) or raise 'gnuplot not found' 59: IO::popen( cmd, "w") { |io| yield io } 60: end
Trivial implementation of the which command that uses the PATH environment variable to attempt to find the given application. The application must be executable and reside in one of the directories in the PATH environment to be found. The first match that is found will be returned.
bin [String] The name of the executable to search for.
Return the full path to the first match or nil if no match is found.
# File lib/gnuplot.rb, line 19 19: def Gnuplot.which ( bin ) 20: return bin if File::executable? bin 21: 22: path = ENV['PATH'] # || ENV['WHAT_EVER_WINDOWS_PATH_VAR_IS'] 23: path.split(File::PATH_SEPARATOR).each do |dir| 24: candidate = File::join dir, bin.strip 25: return candidate if File::executable? candidate 26: end 27: 28: # This is an implementation that works when the which command is 29: # available. 30: # 31: # IO.popen("which #{bin}") { |io| return io.readline.chomp } 32: 33: return nil 34: end