Sha256: 71a41b0183e857a60d9bea203987b201ce6ebcb67ae1589dbb261db884eb12cc

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Mermaid
  class FlowchartDiagram::Link < Dry::Struct
    attribute :from, FlowchartDiagram::Types::String
    attribute :to, FlowchartDiagram::Types::String
    attribute :label, FlowchartDiagram::Types::String.optional.default(nil)
    attribute :type, FlowchartDiagram::Types::String.default('arrow_head')
                                                    .enum('arrow_head',
                                                          'open_link',
                                                          'text_link',
                                                          'dotted',
                                                          'thick',
                                                          'invisible'
                                                    )

    def representation
      case type
      when 'arrow_head'
        if label.nil?
          '-->'
        else
          "-->|#{label_representation}|"
        end
      end
    end

    def label_representation
      ## if label is unicode return it with quotes
      ## else return it without quotes
      if label.nil?
        ''
      else
        if label.ascii_only?
          label
        else
          "\"#{label}\""
        end
      end
    end

    def to_s
       [from, representation, to].join
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mermaid-0.0.1 lib/mermaid/flowchart_diagram/link.rb