Class: DataSeries

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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ DataSeries

Returns a new instance of DataSeries.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
# File 'lib/gnuplotr.rb', line 10

def initialize(name)
  raise ArgumentError, "name must be a Symbol" unless name.kind_of? Symbol
  @name = name
  @width = nil
  @length = 0
  @handle = File.open("#{@name.to_s}.dat", "w")
  @handle.puts "\# #{@name} datafile generated on #{Time.now} by GNUPlotr"
end

Instance Method Details

#<<(ary) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
# File 'lib/gnuplotr.rb', line 19

def <<(ary)
  @width = ary.size unless @width
  raise ArgumentError, "record size mismatch (not #{@width})" unless ary.size == @width
  @handle.puts(ary * "\t")
  @length += 1
end

#closeObject



26
27
28
# File 'lib/gnuplotr.rb', line 26

def close
  @handle.close
end