Class: SvgOptimizer::Plugins::RemoveUnusedNamespace

Inherits:
Base
  • Object
show all
Defined in:
lib/svg_optimizer/plugins/remove_unused_namespace.rb

Instance Attribute Summary

Attributes inherited from Base

#xml

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SvgOptimizer::Plugins::Base

Instance Method Details

#processObject



6
7
8
9
10
# File 'lib/svg_optimizer/plugins/remove_unused_namespace.rb', line 6

def process
  xml.root.namespace_definitions
    .select(&:prefix)
    .each(&method(:remove_unused_ns))
end

#remove_unused_ns(ns) ⇒ Object



12
13
14
15
16
# File 'lib/svg_optimizer/plugins/remove_unused_namespace.rb', line 12

def remove_unused_ns(ns)
  return if xml.xpath("//#{ns.prefix}:*").any?
  source = xml.root.to_s.gsub(/ *xmlns:#{ns.prefix}=".*?"/, "")
  xml.root = Nokogiri::XML(source).root
end