module NumPlot::Conversion

The collection of methods converting ruby objects to gnuplot strings.

@!visibility private

Public Instance Methods

convert_color(color) click to toggle source
# File lib/numplot.rb, line 45
def convert_color(color)
  case color
  when RGB then color.to_gnuplot_string
  when String, Integer then color
  else
    raise TypeError, "Cannot convert #{color.inspect} to gnuplot's color"
  end
end
convert_font(font) click to toggle source
# File lib/numplot.rb, line 54
def convert_font(font)
  case font
  when String then font
  when Font then font.to_gnuplot_string
  else
    raise TypeError, "Cannot convert #{font.inspect} to gnuplot's font"
  end
end
convert_range(range) click to toggle source
# File lib/numplot.rb, line 17
def convert_range(range)
  case range
  when String then range
  when Range then range_pair(range.begin, range.end)
  when Array
    if range.size != 2
      raise TypeError, "Cannot convert #{range.inspect} to gnuplot's range"
    end
    range_pair(range[0], range[1])
  else
    raise TypeError, "Cannot convert #{range.inspect} to gnuplot's range"
  end
end
escape_label(s) click to toggle source
# File lib/numplot.rb, line 67
def escape_label(s)
  s.gsub(/[\^_\{\}@&\\~]/){|s| "\\#{s}"}
end
quote(str) click to toggle source
# File lib/numplot.rb, line 63
def quote(str)
  "\"#{str}\""
end
quote_label(s, enhanced) click to toggle source
# File lib/numplot.rb, line 71
def quote_label(s, enhanced)
  return "'#{s.text}'" if s.kind_of?(EnhancedText)
    
  if enhanced
    "'#{escape_label(s)}'"
  else
    "\"#{s}\""
  end
end
range_bound(x) click to toggle source
# File lib/numplot.rb, line 39
def range_bound(x)
  return "" if Float === x && x.infinite?
  return "" if x.nil?
  x.to_s
end
range_pair(lower, upper) click to toggle source

Convert a pair of lower and upper bounds to the gnuplot “range” parmameter stirng. This method is used for converting ranges and arrays of two elements into strings.

# File lib/numplot.rb, line 35
def range_pair(lower, upper)
  "[#{range_bound(lower)}:#{range_bound(upper)}]"
end