Method: Numo::Gnuplot::OptArg.parse

Defined in:
lib/numo/gnuplot.rb

.parse(*opts) ⇒ Object



433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/numo/gnuplot.rb', line 433

def parse(*opts)
  sep = ","
  a = []
  while opt = opts.shift
    if !opt.kind_of?(Numeric)
      sep = " "
    end
    case opt
    when Symbol
      a << from_symbol(opt)
      case opt
      when :label
        if opts.first.kind_of?(Integer)
          a << opts.shift.to_s
        end
        if opts.first.kind_of?(String)
          a << OptArg.quote(opts.shift)
        end
      when NEED_QUOTE
        if opts.first.kind_of?(String)
          a << OptArg.quote(opts.shift)
        end
      end
    when Array
      a << parse(*opt)
    when Hash
      a << opt.map{|k,v| parse_kv(k,v)}.compact.join(" ")
    when Range
      a << "[#{opt.begin}:#{opt.end}]"
    else
      a << opt.to_s
    end
  end
  a.join(sep)
end