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 =

Since gem uses some modern gnuplot features it's required to have modern gnuplot installed.

5.0

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.max_fit_delayObject


18
19
20
# File 'lib/gnuplotrb/staff/settings.rb', line 18

def max_fit_delay
  @max_fit_delay ||= 5
end

Class Method Details

.available_terminalsObject

Overview

Get list of terminals (png, html, qt, jpeg etc) available for that gnuplot.


47
48
49
50
# File 'lib/gnuplotrb/staff/settings.rb', line 47

def available_terminals
  gnuplot_path
  @available_terminals
end

.gnuplot_pathObject

Overview

Get path that should be used to run gnuplot executable. Default value: 'gnuplot'


25
26
27
28
# File 'lib/gnuplotrb/staff/settings.rb', line 25

def gnuplot_path
  self.gnuplot_path = 'gnuplot' unless defined?(@gnuplot_path)
  @gnuplot_path
end

.gnuplot_path=(path) ⇒ Object

Overview

Set path to gnuplot executable.


33
34
35
36
37
38
39
40
41
# File 'lib/gnuplotrb/staff/settings.rb', line 33

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

Overview

Validates gnuplot version. Compares current gnuplot's version with ::MIN_GNUPLOT_VERSION.

Arguments
  • path - path to gnuplot executable.


67
68
69
70
71
72
73
74
# File 'lib/gnuplotrb/staff/settings.rb', line 67

def validate_version(path)
  @version = IO.popen("#{path} --version")
               .read
               .match(/gnuplot ([^ ]+)/)[1]
               .to_f
  message = "Your Gnuplot version is #{@version}, please update it to at least 5.0"
  fail(ArgumentError, message) if @version < MIN_GNUPLOT_VERSION
end

.versionObject

Overview

Get gnuplot version. Uses gnuplot_path to find gnuplot executable.


56
57
58
59
# File 'lib/gnuplotrb/staff/settings.rb', line 56

def version
  gnuplot_path
  @version
end