Class: Vectory::SvgMapping::Namespace
- Inherits:
-
Object
- Object
- Vectory::SvgMapping::Namespace
- Defined in:
- lib/vectory/svg_mapping.rb
Overview
Namespace helper for XML namespace handling
Instance Method Summary collapse
-
#initialize(xmldoc) ⇒ Namespace
constructor
A new instance of Namespace.
-
#ns(path) ⇒ String
Converts XPath to use document namespace.
Constructor Details
#initialize(xmldoc) ⇒ Namespace
Returns a new instance of Namespace.
34 35 36 |
# File 'lib/vectory/svg_mapping.rb', line 34 def initialize(xmldoc) @namespace = xmldoc.root.namespace end |
Instance Method Details
#ns(path) ⇒ String
Converts XPath to use document namespace
41 42 43 44 45 46 47 48 |
# File 'lib/vectory/svg_mapping.rb', line 41 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 |