Class: Metanorma::Utils::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/image.rb

Instance Method Summary collapse

Constructor Details

#initialize(xmldoc) ⇒ Namespace

Returns a new instance of Namespace.



9
10
11
# File 'lib/utils/image.rb', line 9

def initialize(xmldoc)
  @namespace = xmldoc.root.namespace
end

Instance Method Details

#ns(path) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/utils/image.rb', line 13

def ns(path)
  return path if @namespace.nil?

  path.gsub(%r{/([a-zA-z])}, "/xmlns:\\1")
    .gsub(%r{::([a-zA-z])}, "::xmlns:\\1")
    .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]* ?=)}, "[xmlns:\\1")
    .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*\])}, "[xmlns:\\1")
end