Class: Metanorma::Iso::Sts::Transformer::IdGenerator
- Inherits:
-
Object
- Object
- Metanorma::Iso::Sts::Transformer::IdGenerator
- Defined in:
- lib/metanorma/iso/sts/transformer/id_generator.rb
Instance Method Summary collapse
- #id_for(element) ⇒ Object
-
#initialize(context) ⇒ IdGenerator
constructor
A new instance of IdGenerator.
- #register(source_id, sts_id) ⇒ Object
- #remap(source_id) ⇒ Object
- #section_number(element) ⇒ Object
Constructor Details
#initialize(context) ⇒ IdGenerator
Returns a new instance of IdGenerator.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/metanorma/iso/sts/transformer/id_generator.rb', line 7 def initialize(context) @context = context @id_map = {} @section_counters = { table: 0, figure: 0, formula: 0, biblref: 0, fn: 0, unnumbered_table: 0, } end |
Instance Method Details
#id_for(element) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/metanorma/iso/sts/transformer/id_generator.rb', line 28 def id_for(element) case element when Metanorma::IsoDocument::Sections::IsoForewordSection "sec_foreword" when Metanorma::IsoDocument::Sections::IsoAbstractSection "sec_abstract" when Metanorma::IsoDocument::Sections::IsoClauseSection id_for_clause(element) when Metanorma::IsoDocument::Sections::IsoAnnexSection id_for_annex(element) when Metanorma::IsoDocument::Sections::IsoTermsSection id_for_terms(element) when Metanorma::Document::Components::Tables::TableBlock id_for_table(element) when Metanorma::Document::Components::AncillaryBlocks::FigureBlock id_for_figure(element) when Metanorma::Document::Components::AncillaryBlocks::FormulaBlock id_for_formula(element) when Metanorma::Document::Components::Paragraphs::ParagraphBlock id_for_paragraph(element) when Metanorma::StandardDocument::Sections::StandardReferencesSection id_for_ref_section(element) else id = element.id if element.class.method_defined?(:id) id ? remap(id) : nil end end |
#register(source_id, sts_id) ⇒ Object
20 21 22 |
# File 'lib/metanorma/iso/sts/transformer/id_generator.rb', line 20 def register(source_id, sts_id) @id_map[source_id] = sts_id end |
#remap(source_id) ⇒ Object
24 25 26 |
# File 'lib/metanorma/iso/sts/transformer/id_generator.rb', line 24 def remap(source_id) @id_map[source_id] || source_id end |
#section_number(element) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/metanorma/iso/sts/transformer/id_generator.rb', line 56 def section_number(element) if element.is_a?(Metanorma::IsoDocument::Sections::IsoClauseSection) || element.is_a?(Metanorma::IsoDocument::Sections::IsoAnnexSection) || element.is_a?(Metanorma::IsoDocument::Sections::IsoTermsSection) element.number end end |