Class: Vectory::SvgMapping
- Inherits:
-
Object
- Object
- Vectory::SvgMapping
- Defined in:
- lib/vectory/svg_mapping.rb
Overview
Processes SVG mapping in XML documents.
SvgMapping integrates SVG content into XML documents by:
-
Extracting SVG from image tags or inline <svg> elements
-
Processing <target> elements to build link mappings
-
Applying ID suffixes for uniqueness in multi-document scenarios
-
Simplifying svgmap structure for final output
ID Suffixing
SVG IDs are suffixed in two stages to ensure uniqueness:
-
**ID suffix** (optional) - Derived from document/container identity Provides cross-document uniqueness (e.g., <id>_ISO_17301-1_2016)
-
**Index suffix** - Derived from svgmap position in document Provides multi-svgmap uniqueness (e.g., <id>_000000000)
Final ID: <original_id><id_suffix><index_suffix> Example: fig1_ISO_17301-1_2016_000000000
Defined Under Namespace
Classes: Namespace
Class Method Summary collapse
-
.from_path(path) ⇒ Vectory::SvgMapping
Creates an SvgMapping from an XML file path.
-
.from_xml(xml) ⇒ Vectory::SvgMapping
Creates an SvgMapping from an XML string.
Instance Method Summary collapse
-
#call ⇒ Nokogiri::XML::Document
Processes all svgmap elements in the document.
-
#initialize(doc, local_directory = "", id_suffix: nil) ⇒ SvgMapping
constructor
Initializes a new SvgMapping processor.
-
#to_xml ⇒ String
Processes and returns XML string.
Constructor Details
#initialize(doc, local_directory = "", id_suffix: nil) ⇒ SvgMapping
Initializes a new SvgMapping processor.
82 83 84 85 86 |
# File 'lib/vectory/svg_mapping.rb', line 82 def initialize(doc, local_directory = "", id_suffix: nil) @doc = doc @local_directory = local_directory @id_suffix = id_suffix end |
Class Method Details
.from_path(path) ⇒ Vectory::SvgMapping
Creates an SvgMapping from an XML file path.
63 64 65 |
# File 'lib/vectory/svg_mapping.rb', line 63 def self.from_path(path) new(Nokogiri::XML(File.read(path))) end |
.from_xml(xml) ⇒ Vectory::SvgMapping
Creates an SvgMapping from an XML string.
71 72 73 |
# File 'lib/vectory/svg_mapping.rb', line 71 def self.from_xml(xml) new(Nokogiri::XML(xml)) end |
Instance Method Details
#call ⇒ Nokogiri::XML::Document
Processes all svgmap elements in the document.
91 92 93 94 95 96 97 98 99 |
# File 'lib/vectory/svg_mapping.rb', line 91 def call @namespace = Namespace.new(@doc) @doc.xpath(@namespace.ns("//svgmap")).each_with_index do |svgmap, index| process_svgmap(svgmap, index) end @doc end |
#to_xml ⇒ String
Processes and returns XML string.
104 105 106 |
# File 'lib/vectory/svg_mapping.rb', line 104 def to_xml call.to_xml end |