Module: Pubid::Ccsds::Identifier

Defined in:
lib/pubid/ccsds/identifier.rb

Class Method Summary collapse

Class Method Details

.create(type: nil, **opts) ⇒ Object

Factory that builds a CCSDS identifier from a hash of primitives.

Accepts the field shape used by relaton-data-ccsds index entries: ‘:publisher`, `:number`, `:series`, `:part`, `:book_color`, `:retired`, `:edition`, plus the parsed-shape fields `:type`, `:suffix`, `:language`. CCSDS 2.x maps these as:

* `:series` + `:number`  → combined number ("A" + "20" → "A20")
* `:book_color`          → `:type`            (B/G/M/R/Y/O)
* `:publisher`           → ignored (hardcoded "CCSDS")
* `:retired`             → ignored (no 2.x field)

Supplement subclasses (currently just Corrigendum, via ‘type: :cor`) raise ArgumentError until `base:` kwarg is wired through.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pubid/ccsds/identifier.rb', line 29

def self.create(type: nil, **opts)
  if type
    type_sym = type.to_sym
    base_type_key = Identifiers::Base.type[:key].to_sym

    if type_sym != base_type_key
      supplement = supplement_klass_for(type_sym)
      if supplement
        # TODO(create-shim): supplement subclasses (Corrigendum)
        # require a base_identifier. Wire `base:` kwarg through once
        # a caller needs it.
        raise ArgumentError, "#{supplement} requires a " \
                             "base_identifier; Identifier.create " \
                             "cannot build supplements yet"
      end

      # Not a class-dispatch key — treat as book_color data
      # (e.g. `type: "G"` for Green Book) and merge back into opts.
      opts = opts.merge(type: type)
    end
  end

  Identifiers::Base.new(**coerce_create_attrs(opts))
end

.parse(identifier) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/pubid/ccsds/identifier.rb', line 6

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