Class: Symbol
- Inherits:
-
Object
- Object
- Symbol
- Defined in:
- lib/pson.rb
Instance Method Summary collapse
-
#to_postscript ⇒ Object
Convert this symbol into a PostScript expression evaluating to a PostScript name object.
Instance Method Details
#to_postscript ⇒ Object
Convert this symbol into a PostScript expression evaluating to a PostScript name object. If the string does not look like a PostScript name, the resulting expression will use the [[cvn]] operator to convert a PostScript string into a PostScript name.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pson.rb', line 52 def to_postscript s = self.to_s # Does this symbol parse cleanly if treated as a PostScript name? # We're deliberately conservative here. if s.unpack('C*').all?{ |cp| [ 0x30 .. 0x39, # digits 0x41 .. 0x5A, # uppercase 0x61 .. 0x7A, # lowercase "-_", # special ].any?{ |range| range.include? cp}} then return '/' + s else # If not, represent the symbol as a string and convert it to name in # PostScript. return s.to_postscript + " cvn" end end |