class RGL::DOT::Element

Ancestor of Edge, Node, and Graph.

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
156 def quote_ID(id)
157   # Ensure that the ID is a string.
158   id = id.to_s
159 
160   # Return the ID verbatim if it looks like a name, a number, or HTML.
161   return id if id =~ /\A([[:alpha:]_][[:alnum:]_]*|-?(\.[[:digit:]]+|[[:digit:]]+(\.[[:digit:]]*)?)|<.*>)\Z/m && id[-1] != ?\n
162 
163   # Return a quoted version of the ID otherwise.
164   '"' + id.gsub('\\', '\\\\\\\\').gsub('"', '\\\\"') + '"'
165 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
172 def quote_label(label)
173   # Ensure that the label is a string.
174   label = label.to_s
175 
176   # Return the label verbatim if it looks like a name, a number, or HTML.
177   return label if label =~ /\A([[:alpha:]_][[:alnum:]_]*|-?(\.[[:digit:]]+|[[:digit:]]+(\.[[:digit:]]*)?)|<.*>)\Z/m && label[-1] != ?\n
178 
179   # Return a quoted version of the label otherwise.
180   '"' + label.split(/(\\n|\\r|\\l)/).collect do |part|
181     case part
182       when "\\n", "\\r", "\\l"
183         part
184       else
185         part.gsub('\\', '\\\\\\\\').gsub('"', '\\\\"').gsub("\n", '\\n')
186     end
187   end.join + '"'
188 end