Class: GnuPlotter::DataSet

Inherits:
Object
  • Object
show all
Defined in:
lib/gnuplotter.rb

Overview

Nested class for GnuPlot datasets.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DataSet

Constructor for the DataSet object.



199
200
201
202
203
# File 'lib/gnuplotter.rb', line 199

def initialize(options = {})
  @options = options
  @file    = Tempfile.new("gp")
  @io      = @file.open
end

Instance Method Details

#<<(*obj) ⇒ Object Also known as: write

Write method.



206
207
208
# File 'lib/gnuplotter.rb', line 206

def <<(*obj)
  @io.puts obj.join(" ")
end

#closeObject

Method to close a DataSet temporary file io.



213
214
215
# File 'lib/gnuplotter.rb', line 213

def close
  @io.close unless @io.closed?
end

#deleteObject

Method to delete a DataSet temporary file.



218
219
220
221
# File 'lib/gnuplotter.rb', line 218

def delete
  @io.close unless @io.closed?
  @file.unlink if File.exist? @file.path
end

#format_dataObject

Method that returns data lines from file.



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/gnuplotter.rb', line 245

def format_data
  lines = []

  @io.close if @io.respond_to? :close

  File.open(@file) do |ios|
    ios.each do |line|
      line.chomp!

      lines << line
    end
  end

  lines
end

#format_options(input = nil) ⇒ Object

Method that builds a plot/splot command string from dataset options.



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/gnuplotter.rb', line 224

def format_options(input = nil)
  options = []

  if input
    options << %Q{"-"}
  else
    options << %Q{"#{@file.path}"}
  end

  @options.each do |key, value|
    if value == :true
      options << "#{key}"
    else
      options << "#{key} #{value}"
    end
  end

  options.join(" ")
end