Module: GnuplotRB::Settings
- Defined in:
- lib/gnuplotrb/staff/settings.rb
Overview
This module takes care of path to gnuplot executable and checking its version.
Constant Summary collapse
- MIN_GNUPLOT_VERSION =
GnuplotRB can work with Gnuplot 5.0+
5.0
- DEFAULT_MAX_FIT_DELAY =
5
- DEFAULT_GNUPLOT_PATH =
'gnuplot'
Class Attribute Summary collapse
-
.max_fit_delay ⇒ Integer
Get max fit delay.
Class Method Summary collapse
-
.available_terminals ⇒ Array of String
Get list of terminals (png, html, qt, jpeg etc) available for this gnuplot.
-
.gnuplot_path ⇒ String
Get path that should be used to run gnuplot executable.
-
.gnuplot_path=(path) ⇒ Object
Set path to gnuplot executable.
-
.validate_version(path) ⇒ Object
Validate gnuplot version.
-
.version ⇒ Numeric
Get gnuplot version.
Class Attribute Details
.max_fit_delay ⇒ Integer
Get max fit delay.
Max fit delay (5s by default) is used inside Fit::fit function. If it waits for output more than max_fit_delay seconds this behaviour is considered as errorneus.
22 23 24 |
# File 'lib/gnuplotrb/staff/settings.rb', line 22 def max_fit_delay @max_fit_delay ||= DEFAULT_MAX_FIT_DELAY end |
Class Method Details
.available_terminals ⇒ Array of String
Get list of terminals (png, html, qt, jpeg etc) available for this gnuplot.
52 53 54 55 |
# File 'lib/gnuplotrb/staff/settings.rb', line 52 def available_terminals gnuplot_path @available_terminals end |
.gnuplot_path ⇒ String
Get path that should be used to run gnuplot executable. Default value: ‘gnuplot’.
30 31 32 33 |
# File 'lib/gnuplotrb/staff/settings.rb', line 30 def gnuplot_path self.gnuplot_path = DEFAULT_GNUPLOT_PATH unless defined?(@gnuplot_path) @gnuplot_path end |
.gnuplot_path=(path) ⇒ Object
Set path to gnuplot executable.
39 40 41 42 43 44 45 46 47 |
# File 'lib/gnuplotrb/staff/settings.rb', line 39 def gnuplot_path=(path) validate_version(path) opts = { stdin_data: "set term\n" } @available_terminals = Open3.capture2e(path, **opts) .first .scan(/[:\n] +([a-z][^ ]+)/) .map(&:first) @gnuplot_path = path end |
.validate_version(path) ⇒ Object
Validate gnuplot version. Compares current gnuplot’s version with ::MIN_GNUPLOT_VERSION. Throws exception if version is less than min.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gnuplotrb/staff/settings.rb', line 72 def validate_version(path) @version = IO.popen("#{path} --version") .read .match(/gnuplot ([^ ]+)/)[1] .to_f raise( ArgumentError, "Your Gnuplot version is #{@version}, please update it to at least 5.0" ) if @version < MIN_GNUPLOT_VERSION rescue Errno::ENOENT raise( ArgumentError, "Can't find Gnuplot executable. Please make sure it's installed and added to PATH." ) end |
.version ⇒ Numeric
Get gnuplot version. Uses gnuplot_path to find gnuplot executable.
60 61 62 63 |
# File 'lib/gnuplotrb/staff/settings.rb', line 60 def version gnuplot_path @version end |