Class: GnuPlotter::DataSet
- Inherits:
-
Object
- Object
- GnuPlotter::DataSet
- Defined in:
- lib/gnuplotter.rb
Overview
Nested class for GnuPlot datasets.
Instance Method Summary collapse
-
#<<(*obj) ⇒ Object
(also: #write)
Write method.
-
#close ⇒ Object
Method to close a DataSet temporary file io.
-
#delete ⇒ Object
Method to delete a DataSet temporary file.
-
#format_data ⇒ Object
Method that returns data lines from file.
-
#format_options(input = nil) ⇒ Object
Method that builds a plot/splot command string from dataset options.
-
#initialize(options = {}) ⇒ DataSet
constructor
Constructor for the DataSet object.
Constructor Details
#initialize(options = {}) ⇒ DataSet
Constructor for the DataSet object.
199 200 201 202 203 |
# File 'lib/gnuplotter.rb', line 199 def initialize( = {}) @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 |
#close ⇒ Object
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 |
#delete ⇒ Object
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_data ⇒ Object
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 (input = nil) = [] if input << %Q{"-"} else << %Q{"#{@file.path}"} end @options.each do |key, value| if value == :true << "#{key}" else << "#{key} #{value}" end end .join(" ") end |