-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_task_factory.rb
More file actions
44 lines (40 loc) · 1.16 KB
/
Copy pathplot_task_factory.rb
File metadata and controls
44 lines (40 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'rake'
require 'gnuplot'
class PlotTaskFactory
def initialize params
self.set_params params
end
def set_params params
@task_name = params[:task_name]
@task_description = params[:task_description]
@filename = params[:filename]
@filetype = (params[:filetype] or 'pdf')
@label = params[:label]
@xlabel = params[:xlabel]
@ylabel = params[:ylabel]
@data_sets = params[:data_sets]
end
def define_task
task_body = proc {
Gnuplot.open do |gnu_plot|
Gnuplot::Plot.new( gnu_plot ) do |plot|
plot.title @label
filename = @filename
filename << ".#{@filetype}" unless filename.end_with? @filetype
plot.output filename
plot.terminal @filetype
plot.xlabel @xlabel
plot.ylabel @ylabel
@data_sets.each do |data_set|
plot.data << data_set
end
end
end
puts "plot file '#{@filename}' generated"
system "open -a preview #{@filename}"
}
plot_task_params = [@task_name]
plot_task = Rake::Task.define_task *plot_task_params, &task_body
plot_task.add_description @task_description
end
end