Class: Pubid::Ccsds::Identifier

Inherits:
Identifier
  • Object
show all
Defined in:
lib/pubid/ccsds/identifier.rb

Overview

Abstract root for every CCSDS identifier AND the flavor’s parse entry point — mirrors Pubid::Iso::Identifier / Pubid::Jis::Identifier. Concrete identifiers (Identifiers::Base, Identifiers::Corrigendum) descend from this class, so a parsed CCSDS id is an instance of Pubid::Ccsds::Identifier and relaton-index can pass this class as ‘pubid_class` for from_hash/to_hash.

Keeping the root abstract (it is never itself a serialized type, so it is absent from CCSDS_TYPE_MAP) is what breaks the polymorphic recursion a supplement’s ‘base_identifier` would otherwise hit if it pointed at a concrete type that is also its own superclass.

Direct Known Subclasses

SupplementIdentifier

Constant Summary collapse

CCSDS_TYPE_MAP =

Polymorphic type map for lutaml::Model key_value (de)serialization, mapping each concrete class’s polymorphic_name to its class name.

{
  "pubid:ccsds:base" => "Pubid::Ccsds::Identifiers::Base",
  "pubid:ccsds:corrigendum" => "Pubid::Ccsds::Identifiers::Corrigendum",
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Identifier

#base_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_s, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year

Constructor Details

This class inherits a constructor from Pubid::Identifier

Class Method Details

.from_hash(data, options = {}) ⇒ Object

Dispatch deserialization to the concrete class named by the stored ‘_type`, so `from_hash` rebuilds a Corrigendum rather than a bare root (lutaml resolves `_type` only for validation, not instantiation). Mirrors Pubid::Jis::Identifier.from_hash. The `klass == self` guard lets the matched subclass fall through to lutaml’s inherited from_hash.



70
71
72
73
74
75
76
77
78
# File 'lib/pubid/ccsds/identifier.rb', line 70

def self.from_hash(data, options = {})
  type = data["_type"] || data[:_type]
  klass_name = CCSDS_TYPE_MAP[type]
  if klass_name
    klass = Object.const_get(klass_name)
    return klass.from_hash(data, options) unless klass == self
  end
  super
end

.parse(identifier) ⇒ Object

Parse a CCSDS identifier string into the appropriate identifier object.



56
57
58
59
60
61
62
63
# File 'lib/pubid/ccsds/identifier.rb', line 56

def self.parse(identifier)
  # Apply legacy update_codes normalization first
  normalized = Core::UpdateCodes.apply(identifier, :ccsds)
  parsed = Pubid::Ccsds::Parser.parse(normalized)
  Pubid::Ccsds::Builder.build(parsed)
rescue Parslet::ParseFailed => e
  raise "Failed to parse CCSDS identifier '#{identifier}': #{e.message}"
end

Instance Method Details

#publisherObject



51
52
53
# File 'lib/pubid/ccsds/identifier.rb', line 51

def publisher
  "CCSDS"
end