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.



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

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

Instance Method Details

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

Write method.



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

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

#closeObject

Method to close a DataSet temporary file io.



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

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

#deleteObject

Method to delete a DataSet temporary file.



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

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

#format_dataObject

Method that returns data lines from file.



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

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.



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

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