Class: Pubid::Iana::Identifier

Inherits:
Pubid::Identifier show all
Defined in:
lib/pubid/iana/identifier.rb

Overview

Base class for every IANA identifier AND the flavor's parse/create entry point. Concrete identifiers under Pubid::Iana::Identifiers descend from this class, so a parsed IANA id is an instance of Pubid::Iana::Identifier.

IANA entries are protocol registries, not numbered standards: the value is a hierarchical registry slug (registry before the single "/", optional sub_registry after it). Both are kept verbatim.

Direct Known Subclasses

Pubid::Iana::Identifiers::Registry

Constant Summary collapse

IANA_TYPE_MAP =

Polymorphic type map for lutaml::Model key_value (de)serialization: maps the single Registry subclass's polymorphic_name to its class name so a stored hash rebuilds the correct identifier type via from_hash.

{
  "pubid:iana:registry" => "Pubid::Iana::Identifiers::Registry",
}.freeze
PUBLISHER =

Publisher is always "IANA". A plain constant (not a publisher method) so it doesn't shadow the inherited lutaml publisher attribute, which would otherwise fail serialization type validation.

"IANA"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pubid::Identifier

apply_mappings, #base, #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_supplement_suffix, #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 Attribute Details

#with_publisherObject (readonly)

Render-time flag stashed by #to_s; when false, the "IANA " token is dropped so callers can recover the bare index-key slug.



39
40
41
# File 'lib/pubid/iana/identifier.rb', line 39

def with_publisher
  @with_publisher
end

Class Method Details

.parse(identifier) ⇒ Identifier

Parse an IANA identifier string into an identifier object

Parameters:

  • identifier (String)

    The IANA identifier string to parse

Returns:

  • (Identifier)

    The appropriate identifier object



60
61
62
63
64
65
66
67
68
69
# File 'lib/pubid/iana/identifier.rb', line 60

def self.parse(identifier)
  if identifier.length > Pubid::MAX_INPUT_LENGTH
    raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
  end

  parsed = Parser.parse(identifier)
  Builder.build(parsed)
rescue Parslet::ParseFailed => e
  raise "Failed to parse IANA identifier '#{identifier}': #{e.message}"
end

Instance Method Details

#codeObject

The rendered registry code, e.g. "_6lowpan-parameters/lowpan_nhc".



42
43
44
# File 'lib/pubid/iana/identifier.rb', line 42

def code
  sub_registry ? "#{registry}/#{sub_registry}" : registry
end

#to_s(with_publisher: true, **opts) ⇒ Object

Basic string representation. Delegates to the renderer. Always emits the "IANA " token (the authoritative printed form) unless with_publisher is false, in which case the bare slug is rendered.



49
50
51
52
# File 'lib/pubid/iana/identifier.rb', line 49

def to_s(with_publisher: true, **opts)
  @with_publisher = with_publisher
  render(format: :human, **opts)
end