Sha256: 0467c88b32752dd48d1151480aff9a313e577247df5948b4837bc3ba4b1da251

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

# encoding: utf-8

# mixin Graphviz name space (what ever it belongs)
module Graphviz
  # A name space for all types of diagram figures
  module Diagram
    # Provide an interface for create Graphviz record type labels
    class RecordLabel
      def initialize
        @rows = [] # list of Strings
      end

      # rubocop:disable MethodLength
      def add_row(string, opts = {})
        str = quote(string).chomp
        str = format '<%s> %s', opts[:field_id], str if opts[:field_id]
        if opts[:align]
          case opts[:align].to_sym
          when :left then @rows << str + ' \l'
          when :right then @rows << str + ' \r'
          else
            fail "unsupported align #{opts[:align]}"
          end
        else
          @rows << str + "\n"
        end
      end

      def add_separator
        @rows << '|'
      end

      def to_s
        @rows.join('').chomp.gsub("\n|", '|')
      end

      private

      def quote(label)
        label.gsub(/\[\]\{\}\(\)\s/) { |w| '\\' + w }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
graphviz-diagram-0.0.3 lib/graphviz/diagram/record_label.rb
graphviz-diagram-0.0.2 lib/graphviz/diagram/record_label.rb
graphviz-diagram-0.0.1 lib/graphviz/diagram/record_label.rb