Class: Vectory::SvgMapping::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/vectory/svg_mapping.rb

Instance Method Summary collapse

Constructor Details

#initialize(xmldoc) ⇒ Namespace

Returns a new instance of Namespace.



7
8
9
# File 'lib/vectory/svg_mapping.rb', line 7

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

Instance Method Details

#ns(path) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/vectory/svg_mapping.rb', line 11

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