Class: Numo::Gnuplot::KvItem

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

Constant Summary collapse

NEED_QUOTE =

:nodoc: all

%w[
  background
  cblabel
  clabel
  dashtype
  dt
  font
  format
  format_cb
  format_x
  format_x2
  format_xy
  format_y
  format_y2
  format_z
  output
  rgb
  timefmt
  title
  x2label
  xlabel
  y2label
  ylabel
  zlabel
].map{|x| x.to_sym}

Instance Method Summary collapse

Constructor Details

#initialize(k, v) ⇒ KvItem

Returns a new instance of KvItem.



358
359
360
361
# File 'lib/numo/gnuplot.rb', line 358

def initialize(k,v)
  @k = k
  @v = v
end

Instance Method Details

#kv_to_s(k, v) ⇒ Object



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/numo/gnuplot.rb', line 373

def kv_to_s(k,v)
  if need_quote?(k)
    case v
    when String
      "#{k} #{v.inspect}"
    when Array
      "#{k} #{v[0].inspect} #{OptsToS.new(*v[1..-1])}"
    end
  else
    case v
    when String
      "#{k} #{v}"
    when TrueClass
      "#{k}"
    when NilClass
      nil
    when FalseClass
      nil
    when Array
      if /^#{k}/ =~ "using"
        "#{k} #{v.join(':')}"
      else
        "#{k} #{OptsToS.new(*v)}"
      end
    else
      "#{k} #{OptsToS.new(v)}"
    end
  end
end

#need_quote?(k) ⇒ Boolean

Returns:

  • (Boolean)


363
364
365
366
367
# File 'lib/numo/gnuplot.rb', line 363

def need_quote?(k)
  NEED_QUOTE.any? do |q|
    /^#{k}/ =~ q
  end
end

#to_sObject



369
370
371
# File 'lib/numo/gnuplot.rb', line 369

def to_s
  kv_to_s(@k,@v)
end