File: lbl_string.rb

package info (click to toggle)
ruby-graphviz 1.2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,216 kB
  • sloc: ruby: 7,685; xml: 26; makefile: 17
file content (34 lines) | stat: -rw-r--r-- 790 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require "rexml/document"

class GraphViz
  class Types
    class LblString < Common
      def check(data)
        return data
      end

      def output
        html = /^<(.*)>$/m.match(@data.to_s)
        if html != nil
          xml = "<gv>" + html[1].to_s + "</gv>"
          begin
            doc = REXML::Document.new(xml)
            unless doc.root.text == html[1].to_s
              "<#{html[1]}>"
            else
              @data.to_s.inspect.gsub( "\\\\", "\\" )
            end
          rescue REXML::ParseException => _
            @data.to_s.inspect.gsub( "\\\\", "\\" )
          end
        else
          @data.to_s.inspect.gsub( "\\\\", "\\" )
        end
      end

      alias :to_gv :output
      alias :to_s :output
      alias :to_ruby :output
    end
  end
end