Sha256: bd72346c777419810dced43de71e1d1297dd32c5f355a2ef1009111ad6901fcb

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require "pathname"

module Marmerdo
  class Node
    # @return [Symbol]
    attr_reader :path
    # @return [Symbol]
    attr_reader :name
    # @return [Symbol, nil]
    attr_reader :namespace
    attr_accessor :relationships

    def initialize(path:, name:, namespace:, relationships:)
      @path = path
      @name = name.to_sym
      @namespace = namespace&.to_sym
      @relationships = relationships
    end

    def to_mermaid_str
      str = "class #{name}"

      return str if namespace.nil?

      [
        "namespace #{namespace} {",
        str,
        "}"
      ].join("\n")
    end

    def generate_mermaid_link(output_path, enable_link_extension:)
      path = enable_link_extension ? @path : Pathname.new(@path).sub_ext("").to_s

      output_dir = Pathname.new(output_path).dirname
      relative_path = Pathname.new(path).relative_path_from(output_dir).to_s
      relative_path = "./#{relative_path}" unless relative_path.start_with?("../")
      "link #{name} \"#{relative_path}\""
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
marmerdo-0.3.1 lib/marmerdo/node.rb