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.
198 199 200 201 202 |
# File 'lib/gnuplotter.rb', line 198 def initialize( = {}) = @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 |
#close ⇒ Object
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 |
#delete ⇒ Object
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_data ⇒ Object
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 (input = nil) = [] if input << %Q{"-"} else << %Q{"#{@file.path}"} end .each do |key, value| if value == :true << "#{key}" else << "#{key} #{value}" end end .join(" ") end |