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.



197
198
199
200
201
# File 'lib/gnuplotter.rb', line 197

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

Instance Method Details

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

Write method.



204
205
206
# File 'lib/gnuplotter.rb', line 204

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

#closeObject

Method to close a DataSet temporary file io.



211
212
213
# File 'lib/gnuplotter.rb', line 211

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

#deleteObject

Method to delete a DataSet temporary file.



216
217
218
219
# File 'lib/gnuplotter.rb', line 216

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

#format_dataObject

Method that returns data lines from file.



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

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.



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

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