Class: Gnuplot
- Inherits:
-
Object
- Object
- Gnuplot
- Defined in:
- lib/grada/gnuplot.rb
Class Method Summary collapse
- .candidate?(candidate) ⇒ Boolean
- .find_exec(bin) ⇒ Object
- .gnuplot ⇒ Object
- .open(persist = true, &block) ⇒ Object
Class Method Details
.candidate?(candidate) ⇒ Boolean
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/grada/gnuplot.rb', line 7 def self.candidate?(candidate) return candidate if File::executable? candidate ENV['PATH'].split(File::PATH_SEPARATOR).each do |dir| possible_candidate = File::join dir, candidate.strip return possible_candidate if File::executable? possible_candidate end nil end |
.find_exec(bin) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/grada/gnuplot.rb', line 19 def self.find_exec(bin) bin_list = RUBY_PLATFORM =~ /mswin|mingw/ ? [bin, "#{bin}.exe"] : [bin] bin_list.each do |c| exec = candidate?(c) return exec if exec end nil end |
.gnuplot ⇒ Object
30 31 32 33 34 |
# File 'lib/grada/gnuplot.rb', line 30 def self.gnuplot gnu_exec = find_exec( ENV['RB_GNUPLOT'] || 'gnuplot' ) raise NoGnuPlotExecutableFound unless gnu_exec gnu_exec end |
.open(persist = true, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/grada/gnuplot.rb', line 36 def self.open(persist = true, &block) gnuplot_cmd = gnuplot commands = yield output = StringIO.new Open3::popen3(gnuplot_cmd, '-persist') do |data_in, data_out, stderr, wait_th| data_in << commands[:plot_settings] data_in << commands[:plot_data] data_in.flush sleep 1 while true do window = IO::popen('xprop -name "Gnuplot" WM_NAME 2>/dev/null').gets break unless window sleep 1 end end output.string end |