Class: CA::Gnuplot::DataBlock
- Inherits:
-
Object
- Object
- CA::Gnuplot::DataBlock
- Defined in:
- lib/carray/graphics/gnuplot.rb
Constant Summary collapse
- @@datablock_count =
0
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(processor, *args) ⇒ DataBlock
constructor
A new instance of DataBlock.
- #is_csv? ⇒ Boolean
- #to_ca ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(processor, *args) ⇒ DataBlock
Returns a new instance of DataBlock.
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 |
# File 'lib/carray/graphics/gnuplot.rb', line 1361 def initialize (processor, *args) put_ok = false if args.size == 1 and args.first.is_a?(Symbol) @name = "$" + args.first.to_s @text = processor.put %{ print #{@name}} elsif args.size == 1 and args.first.is_a?(String) @@datablock_count += 1 @name = "$DBLK_#{@@datablock_count}" @text = args.first.dup put_ok = true else @@datablock_count += 1 @name = "$DBLK_#{@@datablock_count}" @text = CArray.join(*args).to_csv @text.gsub!(/UNDEF/,"NaN") put_ok = true end @text.strip! @text.chomp! if put_ok processor.put %{ #{@name} <<__EOD__ #{@text} __EOD__ } end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
1409 1410 1411 |
# File 'lib/carray/graphics/gnuplot.rb', line 1409 def name @name end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
1409 1410 1411 |
# File 'lib/carray/graphics/gnuplot.rb', line 1409 def text @text end |
Instance Method Details
#is_csv? ⇒ Boolean
1389 1390 1391 |
# File 'lib/carray/graphics/gnuplot.rb', line 1389 def is_csv? return (@text =~ /,/) end |
#to_ca ⇒ Object
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 |
# File 'lib/carray/graphics/gnuplot.rb', line 1397 def to_ca data = [] @text.each_line do |line| case line when /^#/ else data << line.strip.split(/ +/) end end return CA_OBJECT(data) end |
#to_s ⇒ Object
1393 1394 1395 |
# File 'lib/carray/graphics/gnuplot.rb', line 1393 def to_s return @text.dup end |