Class: Pubid::Iec::SupplementIdentifier
- Inherits:
-
SingleIdentifier
- Object
- Lutaml::Model::Serializable
- Pubid::Identifier
- Identifier
- SingleIdentifier
- Pubid::Iec::SupplementIdentifier
- Defined in:
- lib/pubid/iec/supplement_identifier.rb
Overview
Identifier that represents a supplement to a base identifier.
Direct Known Subclasses
Identifiers::Amendment, Identifiers::Corrigendum, Identifiers::InterpretationSheet
Constant Summary
Constants inherited from Identifier
Instance Method Summary collapse
- #base_from_kv(model, value) ⇒ Object
-
#base_identifier ⇒ Object
Override base_identifier getter to ensure it’s always created for standalone supplements.
- #base_to_kv(model, doc) ⇒ Object
- #copublishers ⇒ Object
-
#ensure_base_identifier ⇒ Object
Ensure we have a base_identifier for standalone supplements Creates a synthetic base identifier from supplement attributes if needed Returns the base_identifier.
-
#mark_synthetic_standalone! ⇒ Object
Re-engage the standalone synthetic-base state on a deserialized supplement.
-
#number ⇒ Object
Override number getter to trigger swap for standalone supplements.
-
#part ⇒ Object
Override part getter for standalone supplements (part becomes nil after swap).
-
#publisher ⇒ Object
Delegate publisher and copublishers to base_identifier whenever there is a base (a supplement carries the publisher of the document it supplements).
-
#synthetic_base? ⇒ Boolean
Check if this supplement has a synthetic base (created for standalone format).
- #to_s(**opts) ⇒ Object
Methods inherited from SingleIdentifier
#edition_portion, #language_portion, #number_portion, #publisher_portion
Methods inherited from Identifier
#all_parts_from_kv, #all_parts_to_kv, #build_code, build_type_map, #copublishers_from_kv, #copublishers_to_kv, default_publisher, #emit_code, from_hash, #number_from_kv, #number_to_kv, parse, #part_from_kv, #part_to_kv, published_typed_stage, #publisher_from_kv, #publisher_to_kv, #stage, #stage_from_kv, #stage_iteration_from_kv, #stage_iteration_to_kv, #stage_to_kv, #subpart_from_kv, #subpart_to_kv, #type, #year_from_kv, #year_to_kv
Methods inherited from Pubid::Identifier
#eql?, #exclude, #hash, #initialize, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, #render, #resolve_urn_generator, #root, #to_mr_string, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year
Constructor Details
This class inherits a constructor from Pubid::Identifier
Instance Method Details
#base_from_kv(model, value) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 33 def base_from_kv(model, value) return unless value base = ::Pubid::Iec::Identifier.from_hash(value) model.base_identifier = base # A base of the exact SingleIdentifier class is the synthetic self-base # of a standalone supplement ("IEC/FDAM 60038-1"); a real attached base # is always a concrete type (InternationalStandard, etc.). Re-engage the # synthetic-base state so the supplement renders in standalone form # (publisher/TYPE base-number-supp-number) instead of attached form. if base.instance_of?(::Pubid::Iec::SingleIdentifier) model.mark_synthetic_standalone! end end |
#base_identifier ⇒ Object
Override base_identifier getter to ensure it’s always created for standalone supplements
59 60 61 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 59 def base_identifier @base_identifier || ensure_base_identifier end |
#base_to_kv(model, doc) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 17 def base_to_kv(model, doc) base = model.base_identifier return unless base # `base_identifier` synthesises a base for a supplement that has none # (e.g. a bare "+AMD1:2008" nested in a consolidation): a fake doc whose # number equals the supplement's own. It renders nothing and the getter # recreates it identically on load, so don't persist it. A standalone # supplement ("IEC/FDAM 60038-1") instead moves the real base number into # the synthetic base (base.number != own number), which must be kept. return if model.synthetic_base? && base.number.to_s == model.number.to_s doc.add_child(Lutaml::KeyValue::DataModel::Element.new("base", base.to_hash)) end |
#copublishers ⇒ Object
99 100 101 102 103 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 99 def copublishers return @copublishers if @ensuring_base base_identifier ? base_identifier.copublishers : @copublishers end |
#ensure_base_identifier ⇒ Object
Ensure we have a base_identifier for standalone supplements Creates a synthetic base identifier from supplement attributes if needed Returns the base_identifier
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 108 def ensure_base_identifier return @base_identifier if @base_identifier # Guard flag to prevent recursion in number getter @ensuring_base = true # For standalone supplements like "IEC/FDAM 60038-1" # The supplement number is in the `part` attribute, while `number` is the base number # We need to create a synthetic base and use part as the supplement number return nil unless publisher && (number || part) # Capture original values BEFORE marking as synthetic # (otherwise our getters will return swapped values) base_number = number supplement_number = part # NOW mark that this is a synthetic base (after capturing values) @synthetic_base = true # Use SingleIdentifier which has typed_stage attribute base = SingleIdentifier.new base.publisher = publisher base.number = base_number if base_number base.part = nil # Base doesn't have part - part is the supplement number base.subpart = subpart if subpart base.date = date if date # Create typed_stage for the base - use "IS" (International Standard) type # not the supplement type base.typed_stage = Pubid::Components::TypedStage.new( abbr: ["IS"], type_code: :is, stage_code: :undated, ) @base_identifier = base # Store the supplement number for getter override # The original number is the base number (moved to base_identifier) # The original part is the supplement number (what we want to return) @supplement_number = supplement_number @base_identifier ensure @ensuring_base = false end |
#mark_synthetic_standalone! ⇒ Object
Re-engage the standalone synthetic-base state on a deserialized supplement. At this point ‘number` already holds the supplement number (set from the “number” key before “base”), so preserve it as the supplement number and flag the synthetic base.
53 54 55 56 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 53 def mark_synthetic_standalone! @synthetic_base = true @supplement_number = @number end |
#number ⇒ Object
Override number getter to trigger swap for standalone supplements
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 64 def number # Guard against recursion in ensure_base_identifier return @number if @ensuring_base # For standalone supplements, trigger base creation first ensure_base_identifier if @synthetic_base.nil? && publisher && part if @synthetic_base @supplement_number || @number else super end end |
#part ⇒ Object
Override part getter for standalone supplements (part becomes nil after swap)
79 80 81 82 83 84 85 86 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 79 def part # For standalone supplements with synthetic base, part is nil (moved to number) if @synthetic_base nil else super end end |
#publisher ⇒ Object
Delegate publisher and copublishers to base_identifier whenever there is a base (a supplement carries the publisher of the document it supplements). Checking base first — rather than ‘@publisher || base` — is required now that the publisher attribute has an IEC default, which would otherwise mask the delegation.
93 94 95 96 97 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 93 def publisher return @publisher if @ensuring_base base_identifier ? base_identifier.publisher : @publisher end |
#synthetic_base? ⇒ Boolean
Check if this supplement has a synthetic base (created for standalone format)
156 157 158 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 156 def synthetic_base? @synthetic_base ||= false end |
#to_s(**opts) ⇒ Object
160 161 162 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 160 def to_s(**opts) render(format: :human, **opts) end |