Class: Metanorma::Plugin::Plantuml::FilenameResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/plugin/plantuml/filename_resolver.rb

Class Method Summary collapse

Class Method Details

.extract(content) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/metanorma/plugin/plantuml/filename_resolver.rb', line 8

def extract(content)
  first_line = content.lines.first&.strip
  return nil unless first_line

  match = first_line.match(/^@start\w+\s+([^\n]+)/i)
  return nil unless match

  filename = match[1].strip
  return nil if filename.empty?

  filename.gsub(/^["']|["']$/, "")
end

.sanitize(filename) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/metanorma/plugin/plantuml/filename_resolver.rb', line 21

def sanitize(filename)
  result = filename.gsub(/[^\w\-.]/, "_")
  result = result.tr_s("._", "._")
  result = result.gsub(/\.{2,}/, ".")
  result = result.gsub(/_{2,}/, "_")
  strip_special_edges(result)
end