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 ⇒ Object
Override base getter to ensure it's always created for standalone supplements.
- #base_from_kv(model, value) ⇒ Object
- #base_to_kv(model, doc) ⇒ Object
- #copublishers ⇒ Object
-
#ensure_base ⇒ Object
Ensure we have a base for standalone supplements Creates a synthetic base identifier from supplement attributes if needed Returns the base.
-
#mark_synthetic_standalone! ⇒ Object
Re-engage the standalone synthetic-base state on a deserialized supplement.
-
#mr_supplement_suffix ⇒ Object
MR supplement suffix:
/{type}.{number}.{year}(e.g. "/amd.1.2016"). -
#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 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, #day_from_kv, #day_to_kv, default_publisher, #emit_code, #month_from_kv, #month_to_kv, #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, #undated_from_kv, #undated_to_kv, #year_from_kv, #year_to_kv
Methods inherited from Pubid::Identifier
apply_mappings, #base_document, concrete_class_for, #dated_version_of?, #draft_of?, #drop_supplements, #edition_of?, #eql?, #exclude, from_hash, #has_supplement?, #hash, #includes?, #initialize, #matches?, #mr_all_parts, #mr_edition, #mr_languages, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_subpart, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, polymorphic_type_map, #related_to?, #render, #resolve_urn_generator, #root, #sibling_of?, #supplement_of?, #to_hash, #to_mr_string, #to_slug, #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 ⇒ Object
Override base getter to ensure it's always created for standalone supplements
59 60 61 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 59 def base @base || ensure_base end |
#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 = 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_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 return unless base # `base` 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 ? base.copublishers : @copublishers end |
#ensure_base ⇒ Object
Ensure we have a base for standalone supplements Creates a synthetic base identifier from supplement attributes if needed Returns the base
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 return @base if @base # 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 = base # Store the supplement number for getter override # The original number is the base number (moved to base) # The original part is the supplement number (what we want to return) @supplement_number = supplement_number @base 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 |
#mr_supplement_suffix ⇒ Object
MR supplement suffix: /{type}.{number}.{year} (e.g. "/amd.1.2016").
The MrString renderer recurses into base and appends this so the
full supplement chain round-trips losslessly (issue #142).
167 168 169 170 171 172 173 174 175 |
# File 'lib/pubid/iec/supplement_identifier.rb', line 167 def mr_supplement_suffix segments = [] segments << mr_type if mr_type segments << number&.to_s if number segments << date&.year&.to_s if date&.year return nil if segments.empty? segments.join(".") 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 return @number if @ensuring_base # For standalone supplements, trigger base creation first ensure_base 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 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 ? base.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 |