Class: Metanorma::Mirror::IdStrategy::Positional
- Defined in:
- lib/metanorma/mirror/id_strategy/positional.rb
Overview
Assign positional IDs (sec-X.Y.Z, table-N, fig-N, anx-X) to elements that have UUID IDs. Elements with author-assigned explicit IDs are preserved. Cross-reference targets are translated to use the new IDs.
Positional IDs are derived from the element's resolved section number (the "number" attribute on the presentation XML element), which represents the document's structural position.
Example:
UUID element with number "5.4" → id: "sec-5.4"
UUID element with number "A.2" → id: "anx-A.2"
Explicit id "sec-3.1.3.4" → id: "sec-3.1.3.4" (unchanged)
Class Method Summary collapse
-
.categories ⇒ Object
Registry of Metanorma model classes → positional-ID category (:section, :annex, :figure, :table).
- .category_for(element) ⇒ Object
- .register_category(model_class, category) ⇒ Object
- .unregister_category(model_class) ⇒ Object
Instance Method Summary collapse
- #assign_id(element) ⇒ Object
- #finalize!(document) ⇒ Object
-
#initialize ⇒ Positional
constructor
A new instance of Positional.
Constructor Details
#initialize ⇒ Positional
Returns a new instance of Positional.
65 66 67 |
# File 'lib/metanorma/mirror/id_strategy/positional.rb', line 65 def initialize @id_map = {} end |
Class Method Details
.categories ⇒ Object
Registry of Metanorma model classes → positional-ID category (:section, :annex, :figure, :table). Adding new flavors or new model types requires only a new register_category call — no edits to derive/element_category (OCP).
26 27 28 |
# File 'lib/metanorma/mirror/id_strategy/positional.rb', line 26 def categories @categories end |
.category_for(element) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/metanorma/mirror/id_strategy/positional.rb', line 40 def category_for(element) return categories[element.class] if categories.key?(element.class) categories.each do |klass, category| return category if element.is_a?(klass) end nil end |
.register_category(model_class, category) ⇒ Object
30 31 32 33 |
# File 'lib/metanorma/mirror/id_strategy/positional.rb', line 30 def register_category(model_class, category) categories[model_class] = category self end |
.unregister_category(model_class) ⇒ Object
35 36 37 38 |
# File 'lib/metanorma/mirror/id_strategy/positional.rb', line 35 def unregister_category(model_class) categories.delete(model_class) self end |
Instance Method Details
#assign_id(element) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/metanorma/mirror/id_strategy/positional.rb', line 69 def assign_id(element) raw = raw_id(element) return raw unless uuid?(raw) positional = derive(element) return raw unless positional @id_map[raw] = positional positional end |
#finalize!(document) ⇒ Object
80 81 82 83 |
# File 'lib/metanorma/mirror/id_strategy/positional.rb', line 80 def finalize!(document) translate_targets(document) document end |