Class: Lutaml::UmlRepository::Exporters::Markdown::LinkResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/uml_repository/exporters/markdown/link_resolver.rb

Instance Method Summary collapse

Constructor Details

#initialize(indexes) ⇒ LinkResolver

Returns a new instance of LinkResolver.



8
9
10
# File 'lib/lutaml/uml_repository/exporters/markdown/link_resolver.rb', line 8

def initialize(indexes)
  @indexes = indexes
end

Instance Method Details



16
17
18
# File 'lib/lutaml/uml_repository/exporters/markdown/link_resolver.rb', line 16

def class_link(qname)
  "../classes/#{sanitize_filename(qname)}.md"
end

#extract_package_path(qname) ⇒ Object



28
29
30
31
# File 'lib/lutaml/uml_repository/exporters/markdown/link_resolver.rb', line 28

def extract_package_path(qname)
  parts = qname.split("::")
  parts.size > 1 ? parts[0..-2].join("::") : "ModelRoot"
end


12
13
14
# File 'lib/lutaml/uml_repository/exporters/markdown/link_resolver.rb', line 12

def package_link(path)
  "../packages/#{sanitize_filename(path)}.md"
end

#package_path(package) ⇒ Object



20
21
22
# File 'lib/lutaml/uml_repository/exporters/markdown/link_resolver.rb', line 20

def package_path(package)
  @indexes&.dig(:package_to_path, package.xmi_id) || package.name
end

#qualified_name(klass) ⇒ Object



24
25
26
# File 'lib/lutaml/uml_repository/exporters/markdown/link_resolver.rb', line 24

def qualified_name(klass)
  @indexes&.dig(:class_to_qname, klass.xmi_id) || klass.name
end

#sanitize_filename(name) ⇒ Object



33
34
35
# File 'lib/lutaml/uml_repository/exporters/markdown/link_resolver.rb', line 33

def sanitize_filename(name)
  name.gsub("::", "_").gsub(/[^a-zA-Z0-9_\-.]/, "_")
end