Class: GNUPlotr
- Inherits:
-
Object
show all
- Defined in:
- lib/gnuplotr.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(path = nil) ⇒ GNUPlotr
Returns a new instance of GNUPlotr.
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/gnuplotr.rb', line 34
def initialize(path=nil)
@gnuplot_path = (path || find_path)
raise RuntimeError, "Could not find #{@gnuplot_path}" unless File.exist? @gnuplot_path
@gnuplot, @stdout, @stderr = Open3.popen3(@gnuplot_path)
Thread.new { capture(@stdout) {|line| puts "> " + line } }
Thread.new { capture(@stderr) {|line| warn ">>" + line } }
@series = {}
@record = false
@record_list = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/gnuplotr.rb', line 57
def method_missing(name, *args, &block)
options = args.inject("") {|s, t|
s + " " + parse_tokens(t)
}
raw "#{name.to_s.sub(/_/, " ")} #{options}"
end
|
Instance Attribute Details
#gnuplot_path ⇒ Object
Returns the value of attribute gnuplot_path.
33
34
35
|
# File 'lib/gnuplotr.rb', line 33
def gnuplot_path
@gnuplot_path
end
|
#record ⇒ Object
Returns the value of attribute record.
33
34
35
|
# File 'lib/gnuplotr.rb', line 33
def record
@record
end
|
#series ⇒ Object
Returns the value of attribute series.
33
34
35
|
# File 'lib/gnuplotr.rb', line 33
def series
@series
end
|
Instance Method Details
77
78
79
80
|
# File 'lib/gnuplotr.rb', line 77
def dump_input
= "\# Gnuplot inputfile generated on #{Time.now} by GNUPlotr\n"
+ @record_list * "\n"
end
|
#fill_series(name) {|| ... } ⇒ Object
50
51
52
53
54
55
|
# File 'lib/gnuplotr.rb', line 50
def fill_series(name)
raise "Need a block" unless block_given?
new_series(name) unless @series[name]
yield @series[name]
@series[name].close
end
|
#new_series(name) ⇒ Object
45
46
47
48
|
# File 'lib/gnuplotr.rb', line 45
def new_series(name)
raise ArgumentError, "name must be a Symbol" unless name.kind_of? Symbol
@series[name] = DataSeries.new(name)
end
|
#plot(arg, opts = nil) ⇒ Object
69
70
71
|
# File 'lib/gnuplotr.rb', line 69
def plot(arg, opts=nil)
_plot("plot", arg, opts)
end
|
#raw(message) ⇒ Object
64
65
66
67
|
# File 'lib/gnuplotr.rb', line 64
def raw(message)
@record_list << message if @record
@gnuplot.puts message
end
|
#replot(arg, opts = nil) ⇒ Object
73
74
75
|
# File 'lib/gnuplotr.rb', line 73
def replot(arg, opts=nil)
_plot("replot", arg, opts)
end
|
#reset ⇒ Object
82
83
84
|
# File 'lib/gnuplotr.rb', line 82
def reset
@record_list = []
end
|