lib/gnuplotrb/staff/datablock.rb
##
# Instantiate one more Datablock with updated data
# if data stored in here-doc. Append update to file
# if data stored there.
#
# @param data [#to_gnuplot_points] anything with #to_gnuplot_points method
# @return [Datablock] self if data stored in file (see constructor)
# @return [Datablock] new datablock with updated data otherwise
#
# @example
#   data = [[0, 1, 2, 3], [0, 1, 4, 9]] # y = x**2
#   db = Datablock.new(data, false)
#   update = [[4, 5], [16, 25]]
#   updated_db = db.update(update)
#   # now db and updated_db contain DIFFERENT data
#   # db - points with x from 0 up to 3
#   # updated_db - points with x from 0 to 5
#
# @example
#   data = [[0, 1, 2, 3], [0, 1, 4, 9]] # y = x**2
#   db = Datablock.new(data, true)
#   update = [[4, 5], [16, 25]]
#   updated_db = db.update(update)
#   # now db and updated_db contain THE SAME data
#   # because they linked with the same temporary file
#   # db - points with x from 0 up to 5
#   # updated_db - points with x from 0 to 5
Instantiate one more Datablock with updated data
if data stored in here-doc. Append update to file
if data stored there.
Instantiate one more Datablock with updated data if data stored in here - doc . Append update to file if data stored there .
def update(data)
      data_str = data.to_gnuplot_points
      if @stored_in_file
        File.open(@file_name, 'a') { |f| f.puts "\n#{data_str}" }
        self
      else
        Datablock.new("#{@data}\n#{data_str}", false)
      end
    end
def update ( data ) data_str = data . to_gnuplot_points if @stored_in_file File . open ( @file_name , 'a' ) { | f | f . puts "\n#{data_str}" } self else Datablock . new ( "#{@data}\n#{data_str}" , false ) end end
Instantiate one more Datablock with updated data
if data stored in here-doc.
Instantiate one more Datablock with updated data if data stored in here - doc .
self if data stored in file
self if data stored in file
Datablock
new datablock with updated data otherwise
new datablock with updated data otherwise
Datablock
data
anything with #to_gnuplot_points method
anything with #to_gnuplot_points method
example
data = [[0, 1, 2, 3], [0, 1, 4, 9]] # y = x**2 db = Datablock.new(data, false) update = [[4, 5], [16, 25]] updated_db = db.update(update) # now db and updated_db contain DIFFERENT data # db - points with x from 0 up to 3 # updated_db - points with x from 0 to 5
data = [[ 0 1 2 3 ] [ 0 1 4 9 ]] # y = x ** 2 db = Datablock . new ( data false ) update = [[ 4 5 ] [ 16 25 ]] updated_db = db . update ( update ) # now db and updated_db contain DIFFERENT data # db - points with x from 0 up to 3 # updated_db - points with x from 0 to 5
example
data = [[0, 1, 2, 3], [0, 1, 4, 9]] # y = x**2 db = Datablock.new(data, true) update = [[4, 5], [16, 25]] updated_db = db.update(update) # now db and updated_db contain THE SAME data # because they linked with the same temporary file # db - points with x from 0 up to 5 # updated_db - points with x from 0 to 5
data = [[ 0 1 2 3 ] [ 0 1 4 9 ]] # y = x ** 2 db = Datablock . new ( data true ) update = [[ 4 5 ] [ 16 25 ]] updated_db = db . update ( update ) # now db and updated_db contain THE SAME data # because they linked with the same temporary file # db - points with x from 0 up to 5 # updated_db - points with x from 0 to 5