class RGL::DOT::Element
Attributes
name[RW]
options[RW]
Private Instance Methods
quote_ID(id)
click to toggle source
Returns the string given in id within quotes if necessary. Special characters are escaped as necessary.
# File lib/rgl/rdot.rb, line 156 def quote_ID(id) # Ensure that the ID is a string. id = id.to_s # Return the ID verbatim if it looks like a name, a number, or HTML. return id if id =~ /\A([[:alpha:]_][[:alnum:]_]*|-?(\.[[:digit:]]+|[[:digit:]]+(\.[[:digit:]]*)?)|<.*>)\Z/m && id[-1] != ?\n # Return a quoted version of the ID otherwise. '"' + id.gsub('\', '\\\\').gsub('"', '\\"') + '"' end
quote_label(label)
click to toggle source
Returns the string given in label within quotes if necessary. Special characters are escaped as necessary. Labels get special treatment in order to handle embedded n, r, and l sequences which are copied into the new string verbatim.
# File lib/rgl/rdot.rb, line 172 def quote_label(label) # Ensure that the label is a string. label = label.to_s # Return the label verbatim if it looks like a name, a number, or HTML. return label if label =~ /\A([[:alpha:]_][[:alnum:]_]*|-?(\.[[:digit:]]+|[[:digit:]]+(\.[[:digit:]]*)?)|<.*>)\Z/m && label[-1] != ?\n # Return a quoted version of the label otherwise. '"' + label.split(/(\n|\r|\l)/).collect do |part| case part when "\\n", "\\r", "\\l" part else part.gsub('\', '\\\\').gsub('"', '\\"').gsub("\n", '\n') end end.join + '"' end